我之前从未接触过苹果脚本,我只需要一个小脚本,但不知道从哪里开始。
我想做的就是在文件夹操作上运行一个脚本..
基本上当我在文件夹中放入一个rar文件时运行。它需要unrar,然后只有当它是一个电影文件到另一个文件夹时才移动文件??
这可能吗?
由于
利
答案 0 :(得分: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
脚本解决的工作流程:
例如,输入文件夹包含以下文件:
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
)。
注意:上面的脚本可以快速编写并可以进行优化。