Using Illustrator CS4 and CS6 on Mac 10.6:
The save function below works fantastic. However, a file extension is being omitted if the end-user chooses to click on a grayed out file name within the “choose file name” window. In other words, clicking on a file called “myverycoollogo.ai” will become “myverycoollogo”. Illustrator itself does not behave like this, so I was wondering if anybody was aware of a simple code adjustment to address this? I’ll be honest, this is not a showstopper, after all, it just requires one to enter the extension.
Thanks,
-Jeff
on mainAI()
--Put a longer time out function
with timeout of 7200 seconds -- (provides two hours for any script activity)
tell application "Adobe Illustrator"
activate
set meshCount to count every mesh item of document 1
if ((count documents) > 0) then
try
set CurrentMode to color space of current document
end try
if CurrentMode = RGB then
set userResponse to (display dialog "RGB ” Click Cancel (Then Fix File)" buttons {"Continue", "Cancel"} default button 2 with icon 2)
if button returned of userResponse is "No" then return
end if
-- Get the path to the current document, if such a path exists.
try
set origPath to file path of current document as Unicode text
-- Rather uselessly, Script Editor and TextEdit return POSIX paths here.
-- Here's a trap in case Illustrator does the same.
try
origPath as alias
on error
set origPath to origPath as POSIX file as Unicode text
end try
on error
set origPath to ""
end try
-- Set a default save name for the document.
try
set currentName to name of current document
if (currentName does not end with ".ai") then set currentName to currentName & ".ai"
on error
set currentName to "Untitled.ai"
end try
-- Prompt for a save name and location. Default to the document's current location
-- if it has one, otherwise to the last one used by the application.
if ((count origPath) > 0) then
set newFile to (choose file name with prompt "Save this document as." default location (origPath as alias) default name currentName)
else
set newFile to (choose file name with prompt "Save this document as." default name currentName)
end if
-- Check that the ".eps" hasn't been lost from the name.
repeat until ((newFile as Unicode text) ends with ".ai")
set newFile to (choose file name with prompt "The name you choose must have an ".ai" extension. Save this document as." default name ((newFile as Unicode text) & ".ai"))
end repeat
--display dialog "doing this"
-- Create the new file if it doesn't exist.
try
open for access newFile
close access newFile
end try
--display dialog "doing this"
try
save current document in newFile as Illustrator with options {class:Illustrator save options, embed linked files:true, PDF compatible:true, font subset threshold:0.0, compressed:true}
end try
--save current document in newFile as Illustrator
--close current document saving no
end if
end tell
end timeout
end mainAI