我以前从未接触过苹果脚本,我只需要 1 个小脚本,但不知道从哪里开始。
我想要做的就是在文件夹操作上运行一个脚本..
当我将 aa rar 文件放在文件夹中时基本上运行。仅当它是电影文件时才需要解压缩然后将文件移动到另一个文件夹?
这可能吗 ??
谢谢
李
我以前从未接触过苹果脚本,我只需要 1 个小脚本,但不知道从哪里开始。
我想要做的就是在文件夹操作上运行一个脚本..
当我将 aa rar 文件放在文件夹中时基本上运行。仅当它是电影文件时才需要解压缩然后将文件移动到另一个文件夹?
这可能吗 ??
谢谢
李
下载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
脚本的工作流程解释:
例如,输入文件夹包含以下文件:
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
) 会被脚本自动删除。
注意:上面的脚本写的很快,可以优化。