2014-04-07 79 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