Applescript Noob、unar.rar文件并移动包含的文件

Applescript Noob、unar.rar文件并移动包含的文件,applescript,unrar,Applescript,Unrar,我从来没有接触过苹果的脚本之前,我只需要一个小脚本,但不知道从哪里开始 我只想在文件夹操作上运行脚本 当我把一个rar文件放在一个文件夹中时基本上运行。只有当文件是电影文件时,才需要取消归档,然后将其移动到另一个文件夹 这可能吗 谢谢 Lee下载RAR Expander并将应用程序放入应用程序文件夹: 在继续之前,确保打开一次RAR扩展器 现在运行以下AppleScript: property extensionList : {"mp4", "flv"} tell application "

我从来没有接触过苹果的脚本之前,我只需要一个小脚本,但不知道从哪里开始

我只想在文件夹操作上运行脚本

当我把一个rar文件放在一个文件夹中时基本上运行。只有当文件是电影文件时,才需要取消归档,然后将其移动到另一个文件夹

这可能吗

谢谢


Lee

下载
RAR Expander
并将应用程序放入应用程序文件夹:
在继续之前,确保打开一次RAR扩展器

现在运行以下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


注意:上面的脚本编写速度很快,可以进行优化。

我认为这个问题可能是您的一个很好的起点: