2011-08-08 6 views
0

これまでリンゴスクリプトに触れたことはありません。ちょうど1つの小さなスクリプトが必要ですが、どこから起動するのかわかりません。私はフォルダ内の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を開くことを確認してください。

は今、次のAppleScriptを実行します。スクリプトによって

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 

ワークフローは次のように説明し

  • は、(1または複数の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)が自動的に

  • 例については

は、入力フォルダには、以下のファイルが含まれていますスクリプトによって削除されました。

注:上記のスクリプトはすばやく作成され、最適化することができます。

関連する問題