Applescript重命名重复文件:

时间:2013-04-30 15:14:21

标签: applescript rename file-rename

我正在编写一个scipt来创建用户文件夹并将相关的应用程序模板复制到外部媒体卷上的主文件夹中。用户输入的早期信息是通过对话框提供的。 + A3Temp.ptx文件已复制到new_folder,现在我希望将“+ A3Temp.ptx”文件重命名为使用CreationDate_ClientFolder_BrandName_JobName作为其.ptx作为文件名的格式。

这是我到目前为止所做的,但最后阶段仍然会返回类错误。

set temp_name to job_number & creation_date & client_folder & brand_name & job_name
set media_folder to "/Volumes/Media/"
set new_folder to media_folder & temp_name
set template_name to "+A3Temp.ptx"
set session_name to (creation_date & client_folder & brand_name & job_name & ".ptx")

tell application "Finder"
    duplicate POSIX file "/Volumes/Media/+A3Temp.ptx" to POSIX file new_folder
end tell

tell application "Finder"
    set name of POSIX file (new_folder & "/" & template_name) to POSIX file (new_folder & "/" & session_name)
end tell

错误回复为:

"Can't set <<class psxf>> "Volumes/Media/1223456_130430_clientfolder_BrandName_JobName/+A3Temp.ptx of application "Finder" to <<class psxf>> ""Volumes/Media/1223456_130430_clientfolder_BrandName_JobName/130430_clientfolder_BrandName_JobName.ptx" of application "Finder"

我做错了什么?????

1 个答案:

答案 0 :(得分:1)

将文件对象转换为别名:

tell application "Finder"
    set name of (POSIX file "/tmp/a" as alias) to "b"
end tell

如果new_folder不存在,则复制不会创建它:

tell application "Finder"
    make new folder at media_folder with properties {name:temp_folder}
end tell