我在这个AppleScript中添加了注释,解释了脚本的每个部分的作用。就目前而言,它的设计是从内部运行
脚本编辑器
,但它可以很容易地调整为
自动机
工作流。
Copy-n-将脚本粘贴到
脚本编辑器
. 代替
/路径/到/文件夹
包含文件夹的路径
.压敏电阻
文件已定位(保留引号)。使用完整路径,即。
/用户/CK/电影
而不是
~/电影
. 按
Cmd命令
+
K
编译脚本,并检查预运行语法错误等。当字体改变,脚本看起来打印得很漂亮时,点击
Cmd命令
+
R
执行它。
tell application "System Events" to get the files in folder ¬
"/Path/To/Folder" whose name extension is "mov"
set F to the result -- The list of .mov files that need renaming
-- This will be the character used to rejoin pieces
-- of the filename after breaking them apart
set the text item delimiters to "_"
repeat with g in F -- Loop through the file list
-- Get the filename
tell application "System Events" to get name of g
-- Eliminate the version number component of the filename
set r to do shell script ¬
"echo " & quoted form of result & ¬
" | egrep -o '[^_\\.]+'" & ¬
" | egrep -iv 'v\\d+'"
-- Assemble the other components in the new order
get {paragraphs 2 thru -2, paragraph 1} of r
get (result as text) & ".mov"
-- Rename the file to the new name
tell application "System Events" to set name of g to result
end repeat