Applescript从资源复制文件,与Finder,Capture One Pro交互

时间:2018-05-28 12:09:05

标签: applescript

我有一个Applescript应用程序,可以将特定的 .txt 文件和一个空白的 Capture One Pro .session 从应用包资源中复制到所选的新名称和位置用户,然后将打开Capture One(id C1PR)。

脚本正在运行,但我仍然有点新编码,所以我希望有一个更好/更简洁的方式来编写它。 具体来说,如果4 x单独的'显示对话框''选择文件夹'可以替换为2x “选择文件名并提示”

我还没有弄清楚如何使用选择文件名提示,然后创建该文件夹,同时还保留名称输入以生成“newJobName”或“seshName”变量供以后使用上。

非常感谢有关清理此内容的任何建议,以及有关使用用户输入脚本添加中的“选择文件名”提示的任何提示。谢谢!

这是当前的脚本。

set logoIcon to alias ((path to me as string) & "Contents:Resources:Ourlogo.icns")
set bundleResources to (path to me as string) & "Contents:Resources:"
set defaultLocation to (path to desktop) as alias
set newJobname to text returned of (display dialog "TODAY'S JOB NAME:" with title "OurCompany New Job" default answer "Job-2018-00-00" with icon logoIcon)
set newLoc to (choose folder with prompt "CHOOSE SAVE LOCATION FOR TODAY'S JOB:" default location defaultLocation)

tell application "Finder"
    set newJobDirectory to make new folder at newLoc with properties {name:newJobname}
    set getJobBrief to file "job_brief_template.rtf" of (bundleResources as alias) --getting job brief from bundle and renaming to match today's job after duplicating
    duplicate getJobBrief to newJobDirectory
    set name of document file "job_brief_template.rtf" of newJobDirectory to newJobname & ".rtf"
    make new folder at newJobDirectory with properties {name:"Raw Folder"} --creating standard folders required for our daily jobs
    make new folder at newJobDirectory with properties {name:"Mark Ups"}
    make new folder at newJobDirectory with properties {name:"Resources"}
    make new folder at newJobDirectory with properties {name:"JPGS"}
    make new folder at newJobDirectory with properties {name:"No Retouching"}

    set seshName to text returned of (display dialog "TODAY'S CAPTURE SESSION NAME:" default answer newJobname with icon logoIcon) --usually the same as the newJobName but need to give user a choice to ammend it.
    set the clipboard to {text:seshName, Unicode text:seshName} --setting job name to clipboard in case Capture Session doesn't work.

    set targetSesh to (choose folder with prompt "CHOOSE LOCATION FOR TODAY'S CAPTURE SESSION:" default location defaultLocation)
    set newSeshDirectory to make new folder at targetSesh with properties {name:seshName}
    make new folder at newSeshDirectory with properties {name:"Capture"} --creating standard Capture One Pro session folders
    make new folder at newSeshDirectory with properties {name:"Selects"}
    make new folder at newSeshDirectory with properties {name:"Output"}
    make new folder at newSeshDirectory with properties {name:"Trash"}
    set getSeshDoc to file "session.cosessiondb" of (bundleResources as alias) --getting blank session from bundle and renaming to match today's job after duplicating
    duplicate getSeshDoc to newSeshDirectory
    set name of document file "session.cosessiondb" of newSeshDirectory to seshName & ".cosessiondb"
    set openSesh to result --variable to tell Capture One application to open

end tell

1 个答案:

答案 0 :(得分:0)

choose file name返回一个file说明符(文件URL),可以轻松转换为POSIX路径。

这是已清理的版本,该版本使用shell命令mkdir在一行中创建所有文件夹。

set bundleResources to (path to me as string) & "Contents:Resources:"
set defaultLocation to path to desktop
set newJobLocation to (choose file name with prompt "TODAY'S JOB NAME:" default name "Job-2018-00-00" default location defaultLocation) as text

do shell script "/bin/mkdir -p " & quoted form of POSIX path of newJobLocation & "/{'Raw Folder','Mark Ups',Resources,JPGS,'No Retouching'}"
tell application "Finder"
    set jobName to name of folder newJobLocation
    set getJobBrief to file "job_brief_template.rtf" of folder bundleResources
    duplicate getJobBrief to folder newJobLocation
end tell

set newSeshLocation to (choose file name with prompt "TODAY'S CAPTURE SESSION NAME:" default name "Job-2018-00-00" default location defaultLocation) as text
do shell script "/bin/mkdir -p " & quoted form of POSIX path of newSeshLocation & "/{Capture,Selects,Output,Trash}"
tell application "Finder"
    set seshName to name of folder newSeshLocation
    set getSeshDoc to file "session.cosessiondb" of folder bundleResources
    set duplicatedFile to duplicate getSeshDoc to folder newSeshLocation
    set name of duplicatedFile to seshName & ".cosessiondb"
    set the clipboard to {text:seshName, Unicode text:seshName}
end tell
set openSesh to result --variable to tell Capture One application to open