2011-08-08 4 views
0

전에 사과 스크립트를 한번도 만져 본 적이 없으며, 1 개의 작은 스크립트가 필요하지만 어디서부터 시작해야할지 모릅니다. 내가 폴더에 A A RAR 파일을 넣을 때Applescript Noob, unrar .rar 파일 및 포함 된 파일 이동

내가 원하는 모든 폴더 작업에서 스크립트를 실행 ..

은 기본적으로 실행합니다. 그것은 unrar 다음 다른 폴더에 동영상 파일 인 경우에만 파일을 이동해야합니까 ??

가능합니까 ??

감사

+0

이 질문은 좋은 출발점이 될 수 있다고 생각합니다. http://stackoverflow.com/questions/3896175/applescript-processing-files-in-folders-recursively – Asmus

답변

1

다운로드 RAR Expander 및 응용 프로그램 폴더에 응용 프로그램을 드롭 : http://rarexpander.sourceforge.net/Downloads.html
진행하기 전에 한 번 RAR Expander을 열 수 있는지 확인합니다.

이제 다음과 같은 애플 스크립트를 실행 스크립트에 의해

property extensionList : {"mp4", "flv"} 

tell application "Finder" 

    set the sourceFolder to choose folder with prompt "Select Input Folder" 
    set the outputFolder to choose folder with prompt "Select Output Folder" 

    set inputFiles to every file of the sourceFolder whose name extension is "rar" 

    repeat with i from 1 to the count of inputFiles 
     set theArchive to POSIX path of ((item i of inputFiles) as string) 
     tell application "RAR Expander" 
      expand theArchive to POSIX path of outputFolder 
     end tell 
    end repeat 

    set extractedFiles to every file of the outputFolder 

    repeat with i from 1 to the count of extractedFiles 
     if (the name extension of the (item i of extractedFiles) is not in the extensionList) then 
      do shell script "rm -rf " & quoted form of (POSIX path of ((item i of extractedFiles) as string)) 
     end if 
    end repeat 

end tell 

워크 플로우 설명 :

  • 이 결정 (하나 또는 여러 개의 RAR 파일을 포함) 입력 폴더에 있습니다.
  • 출력 폴더 (빈 폴더)를 결정하십시오.
  • 입력 폴더 내의 RAR 보관 파일을 출력 폴더로 추출하십시오.
  • 출력 폴더 내의 파일을 반복합니다.
  • 확장명 목록에 언급 된 확장명을 가진 파일 만 보존합니다.

    Archive_Containing_FLV_File.rar 
    Archive_Containing_MP4_File.rar 
    Archive_Containing_PDF_File.rar 
    

    스크립트를 실행 한 후, 출력 폴더 만 포함 :

    The_Extracted_FLV_File.flv 
    The_Extracted_MP4_File.mp4 
    

    PDF 파일 (The_Extracted_PDF_File.pdf)는 자동입니다

  • 예를 들어

는 입력 폴더에는 다음 파일이 포함되어 있습니다 스크립트에 의해 삭제되었습니다.

참고 : 위의 스크립트는 빠르게 작성되고 최적화 할 수 있습니다.