2014-04-07 57 views
-1

上周我问了一个关于这个脚本的一部分的问题,并且有一些真正有用的回复让我朝正确的方向发送。我意识到我可以在脚本的最后添加一些,这里是我的。这个脚本在80%的时间内完全正常工作 - 当出现错误时它说找不到文档1的属性。我想我通过添加行集mydoc到文档1来解决这个问题。在哪里添加了它,但我认为它仍然是有时被视为未定义的变量。有没有更好的方式来说明这一点?另一个问题是,有时我可能在下载文件夹中有2或3个文件。我需要为每个文件重复吗?目标是在打开Illustrator文档时添加3种专色。 这里是我目前错误:找不到文档1的属性

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

标题应该描述问题。 –

+0

你能否再次格式化代码?它很难读取,因为它是。 – Mark

+0

对不起,关于蹩脚的标题和格式 - 我从工作中发邮件给我自己,并从我的手机上发布,尽管我第一次没有正确格式化。 – jamthelows

回答

2

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

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

file something of folder something of folder something of disk something 

那风格独特的取景器。因此,如果我们需要在Finder之外有用的路径,我们需要将该风格改变为其他程序将理解的内容。您将在我的代码中看到,我让Finder获取了newfo中的所有文件,但是我将它们转换为Illustrator用“作为别名列表”知道的东西。它将所有这些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 
+0

您的脚本非常棒!我曾经工作过的第一部分,但是当我将部件添加到命令Illustrator时,它遇到了问题,因此您的解释非常有用。我真的很困惑与下载文件夹位,我真的很喜欢你的脚本如何消除(别名“Macintosh HD:用户:Yourusernamehere:下载”的文件)的需要。 Illustrator部分直接来自Adobe手册,所以我不明白为什么每次都不工作。 – jamthelows

+0

在某些时候,我可能会尝试完全自动化整个过程(在chrome,filemaker,finder和illustrator之间),但是我认为用javascript试试这个可能是最好的吗?我有很多东西要学习,但感谢帮助!我用你的用户名命名脚本。 – jamthelows

+0

文件夹的东西文件夹东西的磁盘东西我希望我以前发现这一点 - 这应该是一个地方更容易看到新手。 – jamthelows