Reputation: 49
I'm trying to get Illustrator to save all open documents according to the original file name at the end of this script. It will save whichever file comes first but I can't figure out how to loop it back to re-name the remaining file(s).The files are named numerically so sometimes the back will save an other times the front.
-- 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
Many Thanks to you for your help Tim Joe!!!
Upvotes: 0
Views: 182
Reputation: 475
I would do something like the following (may need to tweak a bit):
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
Was a quick glance and don't see the extension in final path variable. Also Kind of weird to see activate after the save.
Update 4/23
Here is your loop, didn't have time to debug
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
Upvotes: 2