0

以下のスクリプトは基本的に、PDF を含むフォルダーを選択し、選択したフォルダーにある PDF のファイル数を取得し、結果をテキスト ファイルに書き込み、そのテキスト ファイルを Excel で開きます。スクリプトは正常に動作しますが、ファイル パス全体を取得します。

結果は次のとおりです。

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:   65

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:       RESENDS   0

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/: 23

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/:     RESENDS   6

箇条書きの前のすべてを削除したい • 次に、列ごとに。このようなもの:

CUSTO_4    BODY    65

CUSTO_4    BODY          RESENDS   0

CUSTO_4    COVERS  23

CUSTO_4    COVERS        RESENDS   6

テキスト項目の区切り記号の概念を理解しようとしており、offset コマンドを使用していますが、それをスクリプトに実装する方法がわかりません。

target_folder を設定して、「ファイルをカウントするために PDF のみを含むターゲット フォルダーを選択してください」というプロンプトでフォルダーを選択し、結果を非表示にすることなく複数の選択を許可します。

    repeat with i from 1 to (count target_folder)
        set thisFolder to (POSIX path of item i of target_folder)

    --Find & count all PDFs in folders selected that DON'T starts with letter R
    set fileCount to do shell script "find " & quoted form of thisFolder & " -type f  -name *.pdf -and -not -iname 'R[0-9-_]*.pdf' | wc -l"

    set results to (results & "" & thisFolder & ":" & fileCount & return)

    --Find & count all PDFs in folders selected that starts with letter R
    set fileCount to do shell script "find " & quoted form of thisFolder & " -type f -iname 'R[0-9-_]*.pdf' | wc -l"

    set results to (results & "" & thisFolder & ":" & tab & tab & "RESENDS" & fileCount & return)

    end repeat



--write results to a txt file

set theFilePath to (path to desktop folder as string) & "PDF File Count.txt"

set theFile to open for access file theFilePath with write permission

try

set eof of theFile to 0

write results to file theFilePath

close access theFile

on error

close access theFile

end try

--Will open the the PDF File Count.txt in Excel
tell application "Microsoft Excel"

activate

open text file filename "PDF File Count.txt"

end tell
4

2 に答える 2

1

AppleScript のテキスト項目区切り文字は、テキストがどのように分割されたり、再構成されたりするかを決定するために使用されます。文字列のテキスト項目を取得すると、文字列は区切り文字ごとに分割され、結果は断片のリストになります。逆に、テキスト項目のリストを文字列に強制すると、各部分の間に区切り文字が使用されて部分が再構築されます。

あなたの例では、次のようなものを使用できます(結果を得るために少しフォーマットを追加しました):

set theList to {¬
    "/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:   65", ¬
    "/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:       RESENDS   0", ¬
    "/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/: 23", ¬
    "/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/:     RESENDS   6"}

set finalResult to {} -- this will be the final result

set tempTID to AppleScript's text item delimiters -- stash the original delimiters
repeat with anItem in theList
    set AppleScript's text item delimiters to "•"
    set pieces to text items of anItem -- break apart at bullets
    log result

    set theFile to (rest of pieces) as text -- drop the first piece and reassemble
    set AppleScript's text item delimiters to "/"
    set pieces to text items of theFile -- now break apart at slashes
    log result

    set lastPiece to last item of pieces -- trim the last piece a bit
    set theCount to 0
    repeat while first character of lastPiece is in {space, ":"}
        set lastPiece to text 2 thru -1 of lastPiece -- trim it
        set theCount to theCount + 1 -- count up trimmed characters
    end repeat
    if theCount > 4 then set lastPiece to tab & tab & lastPiece -- add a little formatting...
    set last item of pieces to lastPiece -- put the trimmed piece back

    set text item delimiters to tab & tab
    set pieces to pieces as text -- put the pieces back together with tabs
    log result

    set end of finalResult to pieces -- store the reassembled text for later
end repeat
set AppleScript's text item delimiters to tempTID -- restore the original delimiters

choose from list finalResult with empty selection allowed -- show the results
于 2012-04-23T22:13:47.327 に答える
0

テキストを操作するために、必ずしもテキスト アイテムの区切り記号を使用する必要はありません。

set xxx to "/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:   65

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:       RESENDS   0

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/: 23

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/:     RESENDS   6"

set yyy to do shell script "echo " & quoted form of xxx & " | grep -o •.* | sed -e 's/•\\(.*\\):\\(.*\\)/\\1\\2/' -e 's/\\//        /'g"

そして他のアプローチ:

set xxx to "/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:   65

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/BODY/:       RESENDS   0

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/: 23

/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•CUSTO_4/COVERS/:     RESENDS   6"

-- break apart and capture original delimiters
set {Astid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "/Volumes/PREPRESS/1_CATALOG/2_Press/PRINT_Catalog/2012/•"}
set yyy to text items 2 thru -1 of xxx
--put together
set AppleScript's text item delimiters to {""}
set yyy to yyy as string

-- break apart
set AppleScript's text item delimiters to ":"
set yyy to text items of yyy
--put together
set AppleScript's text item delimiters to {""}
set yyy to yyy as string

-- break apart
set AppleScript's text item delimiters to "/"
set yyy to text items of yyy
--put together
set AppleScript's text item delimiters to tab
set yyy to yyy as string

-- reset original delimiters
set AppleScript's text item delimiters to Astid
return yyy
于 2012-04-23T19:11:04.567 に答える