用于重命名文件夹中文件的Applescript

时间:2017-02-20 14:51:50

标签: applescript

这里还是Noob /新手

所以我试图重命名文件夹中的文件

set newfoldername to DT & "-" & JobName & " - " & Wedding --Adds Date, Couples name and event type to make directory name

此处有更多代码

set destFolder to loc & newfoldername & ":Final Delivery:DVD:"
tell application "Finder"
   duplicate file sourcedvdtemp to folder destFolder
   set the name of file "DVD_template.dspproj" to newfoldername
end tell

但我刚收到错误

  

"错误" Finder收到错误:无法设置文件\" DVD_template.dspproj \"到\" newfoldername.dspproj \"。"编号-10006来自档案" DVD_template.dspproj""

我尝试了各种各样的方式,无论是否有扩展" newfoldername"在上面设置并创建一个文件夹,用户输入名称

我只是愚蠢或完全错过了什么。

修改

tell application "Finder" to set frontmost to true
set DT to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set JobName to text returned of (display dialog "Please enter the couples name" default answer "Bride & Groom + Surname") --Asks for couples name
set Wedding to text returned of (display dialog "Please enter the type of day" default answer "Wedding") --Asks for type of day, Wedding, Party, etc
--Creates directory with info from above
set loc to (choose folder "Please choose where you would like to save the files") as text --Loc = Location of where directory will be placed
set newfoldername to DT & "-" & JobName & " - " & Wedding --Adds Date, Couples name and event type to make directory name
set folderStructure to "/{Audio/{Music,RAW\\ Audio\\ Cards},Documents,Exports,FCPX\\ Library,Film\\ Poster,Final\\ Delivery/{DVD,USB,WEB},Images/{Graphics,Stills},RAW\\ Cards/{C100-1,C100-2,7D,100D},XML}"
do shell script "mkdir -p " & quoted form of POSIX path of (loc & newfoldername) & folderStructure

set sourcedvdtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:DVD_template.dspproj" --Gets file DVD_template
set sourceusbtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:USB_template.zip" --Gets file USB_template
set sourcewebtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:WEB_template.zip" --Gets file WEB_template
set sourcefcpxtemp to (path to movies folder as text) & "## - WeddingTemplate - ##:FCPX_template.fcpbundle" --Gets file FCPX_template
set sourcefilmpostemp to (path to movies folder as text) & "## - WeddingTemplate - ##:FILM_POSTER_Template.psd" --Gets file FILM_POSTER_template

set destFolder to loc & newfoldername & ":Final Delivery:DVD:"
tell application "Finder"
    duplicate file sourcedvdtemp to folder destFolder
    set the name of file "DVD_template.dspproj" to newfoldername
end tell

set destFolder to loc & newfoldername & ":FCPX Library:"
tell application "Finder"
    duplicate file sourcefcpxtemp to folder destFolder
    set the name of file "FCPX_template.fcpbundle" to newfoldername
end tell

set destFolder to loc & newfoldername & ":Film Poster:"
tell application "Finder"
    duplicate file sourcefilmpostemp to folder destFolder
    set the name of file "FILM_POSTER_Template.psd" to newfoldername
end tell

1 个答案:

答案 0 :(得分:0)

您正尝试在桌面上重命名文件“DVD_template.dspproj”,这显然不存在。桌面文件夹是Finder的 root 文件夹。

Finder的duplicate命令返回重复的文件,因此它只是

tell application "Finder"
   set fileExtension to name extension of file sourcedvdtemp
   set duplicatedFile to duplicate file sourcedvdtemp to folder destFolder
   set name of duplicatedFile to newfoldername & "." & fileExtension
end tell

如果要将文件重命名为newfoldername,则必须复制并添加文件扩展名。

PS:我建议写5次而不是计算模板文件夹

set weddingTemplateFolder to (path to movies folder as text) & "## - WeddingTemplate - ##:"
set sourcedvdtemp to weddingTemplateFolder & "DVD_template.dspproj" --Gets file DVD_template
set sourceusbtemp to weddingTemplateFolder & "USB_template.zip" --Gets file USB_template 
... etc.