2012-04-23 6 views
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 

.

설정 TARGET_FOLDER 당신은 항상 텍스트를 사용할 필요가 없습니다 ""보이지 세트 결과없이 허용 복수 선택과

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 

답변

0

"파일 개수 만 PDF 파일을 포함하는 폴더를 대상으로 선택"메시지와 폴더를 선택합니다

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 
항목 구분 기호는 텍스트를 조작하는 0
+0

Red_Menace & adayzdone. 답장을 보내 주셔서 감사합니다. 그들은 나를 조금 더 잘 이해하는 데 정말로 도움이되었습니다. 적은 코드로 원하는 것을 얻을 수 있기 때문에 쉘 스크립트를 사용하기로 결정했습니다. – nellbern

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