0

I have never ever touched apple script before, i just need 1 small script but don't know where to start.

All i want to do is run a script on folder action..

to basically run when i put a a rar file in a folder. it needs to unrar and then move the file only if it is a movie file to another folder ??

Is this possible ??

Thanks

Lee

Lee
  • 1,280
  • 4
  • 18
  • 35
  • I think this question could be a good starting point for you: http://stackoverflow.com/questions/3896175/applescript-processing-files-in-folders-recursively – Asmus Aug 08 '11 at 15:44

1 Answers1

1

Download RAR Expander and drop the app into the Applications folder: http://rarexpander.sourceforge.net/Downloads.html
Make sure to open RAR Expander once before proceeding.

Now run the following 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

Workflow by script explained:

  • Determine input folder (containing one or multiple RAR files).
  • Determine output folder (empty folder).
  • Extract the RAR archives within the input folder to the output folder.
  • Loop through the files within the output folder.
  • Only preserve the files with extensions mentioned in the extension list.

For Example, the input folder contains the following files:

Archive_Containing_FLV_File.rar
Archive_Containing_MP4_File.rar
Archive_Containing_PDF_File.rar

After running the script, the output folder only contains:

The_Extracted_FLV_File.flv
The_Extracted_MP4_File.mp4

The PDF file (The_Extracted_PDF_File.pdf) is automatically deleted by the script.

Note: The script above is quickly written and can be optimized.

Anne
  • 26,765
  • 9
  • 65
  • 71