Copy link to clipboard
Copied
Hello, I am really beginner in the use of scripts in illustrator so I try my luck here!
I'm looking for a batch action script that would save my Illustrator CC files to Illustrator CS6, with a suffix on the file name: "-CS6". This would give "date-name-version-CS6". How can I do this? Thank you for your answers !
Copy link to clipboard
Copied
Hey!
You can save the current document with something like this:
var doc = app.activeDocument; // get a reference to the current active document
var filename = doc.fullName; // get the full name and path of the file
filename = filename.substr( 0, filename.lastIndexOf( '.' ) ); // strip off the file ending, assumes that the filename has an extension at the end
filename += "-CS6.ai" // append "-CS6" to the end of the name
var saveOpts = new IllustratorSaveOptions();
saveOpts.compatibility = Compatibility.ILLUSTRATOR16; // specify AI version number
doc.saveAs( filename, saveOpts ); // save out the file to the new path with the specified save options
doc.close(); // close the file
You'll still need to loop through all the files, here's some documentation on loops.
Also! Note that this script assumes that the file will already have an extension, so it's "fullName" property would be something like
"~/Documents/myFile.ai"
in this case it has to strip the ".ai" off before it can add the "-CS6". If it hasn't been saved yet, then I think you should be able to just comment out line 4.
Good luck!
Copy link to clipboard
Copied
Whaouw, thanks ! I'll try your code asap !
Copy link to clipboard
Copied
Apparently it doesn't work cause of an error line 4. The document has been already saved into CC version, is that the cause?
Copy link to clipboard
Copied
Hi simon.chasseloup,
there are several ways to do this.
One simple way:
Replace this line
var filename = doc.fullName; // get the full name and path of the file
with this
var filename = doc.fullName.toString(); // get the full name and path of the file
--------------------------------------------------------------------
Or you can replace this part (of the code written by zertle​)
var filename = doc.fullName; // get the full name and path of the file
filename = filename.substr( 0, filename.lastIndexOf( '.' ) ); // strip off the file ending, assumes that the filename has an extension at the end
filename += "-CS6.ai" // append "-CS6" to the end of the name
with this part
var filename = doc.name; // get the name of the file
var filepath = doc.path; // get the path of the file
filename = filename.replace( /\.(ai)?$/, "-CS6.ai" ); // replace ".ai" with "-CS6.ai" at the end of the name
filename = filepath+"/"+filename; // set the full name and path of the file
Or, or, or …
Have fun