0

我以前从未接触过苹果脚本,我只需要 1 个小脚本,但不知道从哪里开始。

我想要做的就是在文件夹操作上运行一个脚本..

当我将 aa rar 文件放在文件夹中时基本上运行。仅当它是电影文件时才需要解压缩然后将文件移动到另一个文件夹?

这可能吗 ??

谢谢

4

1 回答 1

1

下载RAR Expander应用程序并将其放入 Applications 文件夹: 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

脚本的工作流程解释:

  • 确定输入文件夹(包含一个或多个 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) 会被脚本自动删除。

注意:上面的脚本写的很快,可以优化。

于 2011-08-14T00:21:13.197 回答