Applescript - 将文件复制到文件夹
Applescript - duplicate file to folder
(菜鸟/新手) 在这里我在网上做了很多搜索,但无法让它工作
我正在尝试将文件从预定位置复制到脚本中新创建的文件夹中。
该脚本基本上要求提供一些信息,并使用这些信息和其中的一组预定义文件夹创建一个文件夹结构。从那里我希望它从 HDD 上的模板文件夹复制一些模板文件(.psd .fcpbundle 等)。
我的代码如下,现在一切正常,直到它尝试复制文件
tell application "Finder"
set JobName to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set DT 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" --Loc = Location of where directory will be placed
set newfoldername to JobName & " - " & DT & " - " & Wedding --Adds Date, Couples name and event type to make directory name
--Creates parent directory
set newfo to make new folder at loc with properties {name:newfoldername} --Directory name defined
set audio to make new folder at newfo with properties {name:"Audio"} --creates Audio Directory
set doc to make new folder at newfo with properties {name:"Documents"} --creates Documents Directory
set exports to make new folder at newfo with properties {name:"Exports"} --creates Exports Directory
set fpcx to make new folder at newfo with properties {name:"FCPX Library"} --creates FCPX Directory
set filmposter to make new folder at newfo with properties {name:"Film Poster"} --creates FilmPoster Directory
set finaldel to make new folder at newfo with properties {name:"Final Delivery"} --creates Final Delivery Directory
set images to make new folder at newfo with properties {name:"Images"} --creates Images Directory
set rawcards to make new folder at newfo with properties {name:"RAW Cards"} --creates RAW Cards Directory
set xml to make new folder at newfo with properties {name:"XML"} --creates XML Directory
--Creates sub-folders
set submusic to make new folder at audio with properties {name:"Music"} --creates Music in Audio Directory
set subrawaudio to make new folder at audio with properties {name:"RAW Audio Cards"} --creates RAW Audio Cards in Audio Directory
set subdvd to make new folder at finaldel with properties {name:"DVD"} --creates DVD in Final Delivery Directory
set subusb to make new folder at finaldel with properties {name:"USB"} --creates USB in Final Delivery Directory
set subweb to make new folder at finaldel with properties {name:"WEB"} --creates WEB in Final Delivery Directory
set subgraphics to make new folder at images with properties {name:"Graphics"} --creates Graphics in Images Directory
set substills to make new folder at images with properties {name:"Stills"} --creates Stills in Graphics Directory
set subcam_1 to make new folder at rawcards with properties {name:"Cam-1"} --creates Cam-1 in RAW Cards Directory
set subcam_2 to make new folder at rawcards with properties {name:"Cam-2"} --creates Cam-2 in RAW Cards Directory
set subcam_3 to make new folder at rawcards with properties {name:"Cam-3"} --creates Cam-3 in RAW Cards Directory
--Moves files from template directory to working directory
set sourceFile to POSIX file "/Users/ricoh-admin/Movies/WeddingTemplate Creator/2005_0001.rtf"
set destFolder to POSIX file "loc & finaldel & subdvd"
tell application "Finder"
duplicate POSIX file sourceFile to destFolder
end tell
结束讲述
任何帮助将不胜感激,并知道我哪里出错了等等
您混淆了 POSIX 路径和 HFS 路径。
此版本通过 shell 在一行中创建整个文件夹结构(这需要斜线分隔 POSIX 路径)
Finder 复制需要冒号分隔的 HFS 路径的 RTF 文件。
tell application "Finder" to set frontmost to true
set JobName to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set DT 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 JobName & " - " & DT & " - " & 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/{Cam-1,Cam-2,Cam-3},XML}"
do shell script "mkdir -p " & quoted form of POSIX path of (loc & newfoldername) & folderStructure
set sourceFile to (path to movies folder as text) & "WeddingTemplate Creator:2005_0001.rtf"
set destFolder to loc & newfoldername & ":Final Delivery:DVD:"
tell application "Finder"
duplicate file sourceFile to folder destFolder
end tell
(菜鸟/新手) 在这里我在网上做了很多搜索,但无法让它工作
我正在尝试将文件从预定位置复制到脚本中新创建的文件夹中。
该脚本基本上要求提供一些信息,并使用这些信息和其中的一组预定义文件夹创建一个文件夹结构。从那里我希望它从 HDD 上的模板文件夹复制一些模板文件(.psd .fcpbundle 等)。
我的代码如下,现在一切正常,直到它尝试复制文件
tell application "Finder"
set JobName to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set DT 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" --Loc = Location of where directory will be placed
set newfoldername to JobName & " - " & DT & " - " & Wedding --Adds Date, Couples name and event type to make directory name
--Creates parent directory
set newfo to make new folder at loc with properties {name:newfoldername} --Directory name defined
set audio to make new folder at newfo with properties {name:"Audio"} --creates Audio Directory
set doc to make new folder at newfo with properties {name:"Documents"} --creates Documents Directory
set exports to make new folder at newfo with properties {name:"Exports"} --creates Exports Directory
set fpcx to make new folder at newfo with properties {name:"FCPX Library"} --creates FCPX Directory
set filmposter to make new folder at newfo with properties {name:"Film Poster"} --creates FilmPoster Directory
set finaldel to make new folder at newfo with properties {name:"Final Delivery"} --creates Final Delivery Directory
set images to make new folder at newfo with properties {name:"Images"} --creates Images Directory
set rawcards to make new folder at newfo with properties {name:"RAW Cards"} --creates RAW Cards Directory
set xml to make new folder at newfo with properties {name:"XML"} --creates XML Directory
--Creates sub-folders
set submusic to make new folder at audio with properties {name:"Music"} --creates Music in Audio Directory
set subrawaudio to make new folder at audio with properties {name:"RAW Audio Cards"} --creates RAW Audio Cards in Audio Directory
set subdvd to make new folder at finaldel with properties {name:"DVD"} --creates DVD in Final Delivery Directory
set subusb to make new folder at finaldel with properties {name:"USB"} --creates USB in Final Delivery Directory
set subweb to make new folder at finaldel with properties {name:"WEB"} --creates WEB in Final Delivery Directory
set subgraphics to make new folder at images with properties {name:"Graphics"} --creates Graphics in Images Directory
set substills to make new folder at images with properties {name:"Stills"} --creates Stills in Graphics Directory
set subcam_1 to make new folder at rawcards with properties {name:"Cam-1"} --creates Cam-1 in RAW Cards Directory
set subcam_2 to make new folder at rawcards with properties {name:"Cam-2"} --creates Cam-2 in RAW Cards Directory
set subcam_3 to make new folder at rawcards with properties {name:"Cam-3"} --creates Cam-3 in RAW Cards Directory
--Moves files from template directory to working directory
set sourceFile to POSIX file "/Users/ricoh-admin/Movies/WeddingTemplate Creator/2005_0001.rtf"
set destFolder to POSIX file "loc & finaldel & subdvd"
tell application "Finder"
duplicate POSIX file sourceFile to destFolder
end tell
结束讲述
任何帮助将不胜感激,并知道我哪里出错了等等
您混淆了 POSIX 路径和 HFS 路径。
此版本通过 shell 在一行中创建整个文件夹结构(这需要斜线分隔 POSIX 路径)
Finder 复制需要冒号分隔的 HFS 路径的 RTF 文件。
tell application "Finder" to set frontmost to true
set JobName to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set DT 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 JobName & " - " & DT & " - " & 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/{Cam-1,Cam-2,Cam-3},XML}"
do shell script "mkdir -p " & quoted form of POSIX path of (loc & newfoldername) & folderStructure
set sourceFile to (path to movies folder as text) & "WeddingTemplate Creator:2005_0001.rtf"
set destFolder to loc & newfoldername & ":Final Delivery:DVD:"
tell application "Finder"
duplicate file sourceFile to folder destFolder
end tell