【发布时间】:2016-05-13 16:10:55
【问题描述】:
我正在尝试在 Mac 上的 Automator 中创建一个文件夹操作,当一个新文件被放入我指定的文件夹时,会打开一个对话框,询问我要放入哪个文件 - 然后,根据该选择,将自动将其重命名为对话框返回,理想情况下是今天日期的变量(同时保留相同的扩展名)。
AppleScripts 很新,但这是我迄今为止所拥有的,它没有给我任何错误,但也没有做任何事情:
on run
set theChoice to {"Option1", "Option2", "Option3", "Option4", "Other"}
set selected to {choose from list theChoice}
if selected is "Option1" then
tell application "Finder"
set currentFile to name of (selection as alias)
set currentName to name of currentFile
set name of currentFile to "Option1" & "." & name extension of currentFile
end tell
else if selected is "Option2" then
tell application "Finder"
set currentFile to name of (selection as alias)
set currentName to name of currentFile
set name of currentFile to "Option2" & "." & name extension of currentFile
end tell
else if selected is "Option3" then
tell application "Finder"
set currentFile to name of (selection as alias)
set currentName to name of currentFile
set name of currentFile to "Option3" & "." & name extension of currentFile
end tell
else if selected is "Option4" then
tell application "Finder"
set currentFile to name of (selection as alias)
set currentName to name of currentFile
set name of currentFile to "Option4" & "." & name extension of currentFile
end tell
else
tell application "Finder"
set currentFile to name of (selection as alias)
set currentName to name of currentFile
set name of currentFile to alias & "." & name extension of currentFile
end tell
end if
end run
在弄清楚这部分之后,我还希望在每个文件名的末尾添加一个今天的日期(例如“_20160510”)变量,所以如果这也可以包含,那就太好了。
【问题讨论】:
-
您只更改了临时变量
currentFile的名称。您可能需要像set name of (selection as alias) to currentFile这样的东西作为最后一步。 -
@PaulR 谢谢 -- 我试过
tell application "Finder" set currentFile to name of (selection as alias) set currentName to name of currentFile set name of currentFile to "Option1" & "." & name extension of currentFile set name of (selection as alias) to currentFile end tell但它似乎没有做任何事情。
标签: applescript file-rename automator