在applescript工作流程结束时无法重复正确

时间:2014-04-21 19:10:20

标签: applescript

我试图让Illustrator根据此脚本末尾的原始文件名保存所有打开的文档。它将保存最先出现的文件,但我无法弄清楚如何将其循环回来重新命名剩余的文件。这些文件以数字命名,因此有时后面会保留前面的其他文件。 / p>

 -- get JobName
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")

-- setup folder paths
set loc to path to desktop as text
set downloadsFolder to path to downloads folder as text
set newfo to loc & JobName & ":"
set newfoSeps to newfo & JobName & "_Seps" & ":"

-- make sure all of the folders exist
tell application "Finder"
if not (exists folder newfo) then
    make new folder at loc with properties {name:JobName}
end if

if not (exists folder newfoSeps) then
    make new folder at folder newfo with properties {name:JobName & "_Seps"}
end if

end tell

set the clipboard to JobName -- this is not a Finder command so we do not put it in the Finder block of code

-- move files to newfo and get a list of them
tell application "Finder"
open folder newfo
move (files of folder downloadsFolder) to folder newfo
set newfoFiles to (files of folder newfo) as alias list
set bounds of front window to {1648, 268, 2418, 706}
end tell

-- open each file in Illustrator and make spot colors
repeat with aFile in newfoFiles
tell application "Adobe Illustrator"
    activate
    open aFile
    set WindowList to name of documents --List of every open documents name repeat with CurrentWindow in WindowList 
    set theName to name of current document
    set theNamecount to count of theName
    set theOutdatedPathObj to the file path of current document
    set thePath to (POSIX path of theOutdatedPathObj) as string
    set pathCount to count of thePath
    set pathCount to (pathCount - theNamecount)
    set newPath to (text 1 thru pathCount of thePath)

    tell document 1

        set docColorSpace to color space
        if (docColorSpace is CMYK) then
            set SpotColor1 to {cyan:21.0, magenta:0, yellow:100.0, black:0.0}
            set SpotColor2 to {cyan:11.0, magenta:100, yellow:30.0, black:0.0}
            set SpotColor3 to {cyan:0.0, magenta:0, yellow:0.0, black:100.0}

        else
            set SpotColor1 to {red:206.0, green:219.0, blue:41.0}
            set SpotColor2 to {red:215.0, green:23.0, blue:111.0}
            set SpotColor3 to {red:35.0, green:34.0, blue:33.0}
        end if

        make new spot with properties {name:"Highlight White", color type:spot color, color:SpotColor1}
        make new spot with properties {name:"Under Base", color type:spot color, color:SpotColor2}
        make new spot with properties {name:"Spot Black", color type:spot color, color:SpotColor3}
    end tell
    try
        if theName contains "back" then set newName to JobName & "_FB"

        if theName contains "front" then set newName to JobName & "_FF"

        set finalPath to newPath & newName
        (save current document in file finalPath as Illustrator) -- make sure finalPath looks like this (... folder:folder:Filename.ai) Name extension is important

    end try

end tell

end repeat

end

非常感谢你的帮助Tim Joe !!!

1 个答案:

答案 0 :(得分:2)

我会做类似以下的事情(可能需要调整一下):

    repeat CurrentDoc in OpenDocList
    tell application "Adobe Illustrator"
    active -- the current doc

    save current document in file finalPath as Illustrator -- make sure to have full file path including file extension.

    close -- if wanted
    end tell
    end repeat

快速浏览一下,看不到最终路径变量的扩展名。还有一种奇怪的看法在保存后激活。

更新4/23

这是你的循环,没有时间调试

tell application "Adobe Illustrator"
    activate
    set WindowList to name of documents --List of every open documents name
    repeat with CurrentWindow in WindowList
        open aFile
set theName to name of current document
    set theNamecount to count of theName
    set theOutdatedPathObj to the file path of current document
    set thePath to (POSIX path of theOutdatedPathObj) as string
    set pathCount to count of thePath
    set pathCount to (pathCount - theNamecount)
    set newPath to (text 1 thru pathCount of thePath)
    tell document 1
        set docColorSpace to color space
        if (docColorSpace is CMYK) then
            set SpotColor1 to {cyan:21.0, magenta:0, yellow:100.0, black:0.0}
            set SpotColor2 to {cyan:11.0, magenta:100, yellow:30.0, black:0.0}
            set SpotColor3 to {cyan:0.0, magenta:0, yellow:0.0, black:100.0}
        else
            set SpotColor1 to {red:206.0, green:219.0, blue:41.0}
            set SpotColor2 to {red:215.0, green:23.0, blue:111.0}
            set SpotColor3 to {red:35.0, green:34.0, blue:33.0}
        end if

        make new spot with properties {name:"Highlight White", color type:spot color, color:SpotColor1}
        make new spot with properties {name:"Under Base", color type:spot color, color:SpotColor2}
        make new spot with properties {name:"Spot Black", color type:spot color, color:SpotColor3}
    end tell

 try
        if theName contains "back" then
            set newName to JobName & "_FB"
        else
            if theName contains "front" then
                set newName to JobName & "_FF"

                set finalPath to newPath & newName
                (save current document in file finalPath as Illustrator) -- make sure finalPath looks like this (... folder:folder:Filename.ai) Name extension is important

            end if
        end if
    end try
    end repeat
end tell