错误:无法找到文档1的属性

时间:2014-04-07 22:23:12

标签: applescript

上周我问了一个关于这个剧本的一部分的问题,并且有几个非常有用的回复让我朝着正确的方向前进。我意识到我可以在脚本的末尾添加更多内容,这就是我所拥有的。这个脚本在大约80%的时间内完美地工作 - 当它出现错误时它说找不到文档1的属性。我想我通过将行集mydoc添加到文档1来修复它。它添加了但是我认为它仍然是有时被视为未定义的变量。是否有更好的方式来陈述这一点?另一个问题是,有时我可能在下载文件夹中有2或3个文件。我需要为每个文件重复一次吗?目标是在打开时将3种专色添加到插图文档中。 这是我目前的

tell application "Finder"
set JobName to text returned of (display dialog "Please enter Job Name:" default answer    "Job_Name")
set loc to desktop
set newfoldername to JobName
set newfo to make new folder at loc with properties {name:newfoldername}
make new folder at newfo with properties {name:JobName & "_Seps"}
make new folder at newfo with properties {name:JobName & "_DTG"}
set the clipboard to JobName
end tell

tell application "Finder"
open folder JobName
move (files of alias "Macintosh HD:Users:username:Downloads") to newfo
end tell
tell application "Adobe Illustrator"
open files in newfo
end tell

tell application "Adobe Illustrator"
set mydoc to document 1
set docColorSpace to color space of document 1
if (docColorSpace is CMYK) then
set SpotColor to {cyan:21.0, magenta:0, yellow:100.0, black:0.0}
else
set SpotColor to {red:206.0, green:219.0, blue:41.0}
end if
make new spot in document 1 with properties {name:"Highlight White", color type:spot color,  color:SpotColor}
end tell
tell application "Adobe Illustrator"
set docColorSpace to color space of document 1
if (docColorSpace is CMYK) then
set SpotColor to {cyan:11.0, magenta:100, yellow:30.0, black:0.0}
else
set SpotColor to {red:215.0, green:23.0, blue:111.0}
end if
make new spot in document 1 with properties {name:"Under Base", color type:spot color,   color:SpotColor}
end tell

tell application "Adobe Illustrator"
set docColorSpace to color space of document 1
if (docColorSpace is CMYK) then
set SpotColor to {cyan:0.0, magenta:0, yellow:0.0, black:100.0}
else
set SpotColor to {red:35.0, green:34.0, blue:33.0}
end if
make new spot in document 1 with properties {name:"Spot Black", color type:spot color, color:SpotColor}
end tell

1 个答案:

答案 0 :(得分:2)

你的代码有很多问题,所以我为你重写了它。请注意,我没有检查Illustrator代码,因为我没有Illustrator ...所以如果它不起作用,你只需要调整它。

您的代码的主要问题是newfo。创建该文件夹时Finder生成的路径采用的格式仅为Finder可以理解的格式。 Illustrator不会理解这种格式。这只是你经验所知的。 Finder路径被描述为......

file something of folder something of folder something of disk something

这种风格是Finder独有的。因此,如果我们需要在Finder之外使用该路径,我们需要将该样式更改为其他程序将理解的内容。您将在下面的代码中看到我让Finder获取newfo中的所有文件,但我将它们转换为Illustrator将“as alias list”知道的内容。它会转换所有程序都能理解的别名引用中的所有Finder引用。

所以希望这段代码可以帮助你。继续练习,这是变得更好的唯一方法。祝你好运。

-- 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" & ":"
set newfoDTG to newfo & JobName & "_DTG" & ":"

-- 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

    if not (exists folder newfoDTG) then
        make new folder at folder newfo with properties {name:JobName & "_DTG"}
    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
end tell

-- open each file in Illustrator and do your stuff
repeat with aFile in newfoFiles
    tell application "Adobe Illustrator"
        open aFile
        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
    end tell
end repeat