Skip to main content
Disposition_Dev
Legend
January 27, 2015
Question

Javascript to save as template file in predetermined directory with prompt for filename.

  • January 27, 2015
  • 2 replies
  • 891 views

I've seen a bunch of examples of how to save a regular illustrator file, but I can't seem to find the syntax for saving a file as a .ait file? Am i just missing something incredibly obvious here?? I know this is not right at all.. but this is what i was able to piece together from others' questions.. But i don't see where or how it calls out what kind of file it's saving..?

anyone care to explain the logic in the newName variable? i copied that directly from another post (and edited the file name at the end). What does "/ARTE\..{2,4}$/i" even mean?

I'd also like to suppress dialogs while saving as well.

thanks all.

var sourceName = app.activeDocument.name;

var dest = ('/Volumes/customization/library/cads/');

function saveAsTemplate(destination){

    if(app.documents.length > 0){

        var docRef = app.activeDocument;

        var cadNumber = prompt("What's the number of this CAD?");

        var newName = (sourceName.replace (/ARTE\..{2,4}$/i,'FD-SLOW-SS-' + cadNumber +'.ait');

        var AIT = new File(destination);

        docRef.saveAs(AIT);

    }

} //end function

saveAsTemplate(dest);

This topic has been closed for replies.

2 replies

pixxxelschubser
Community Expert
Community Expert
January 28, 2015

Hi williamadowling,

IMHO it is not possible to save a file as *.ait with scripting (but I don't know).

williamadowling schrieb:

… What does "/ARTE\..{2,4}$/i" even mean? …

This is a part of one of my older threads with the member Ferrarezzi.

This part of the script in this thread:

var substituir_sourceName = sourceName.replace (/ARTE\..{2,4}$/i,'DIGITAL.ai');

means:

find ARTE and a dot and two or three or four characters before the end of the filename – and replace with DIGITAL.ai

e.g.:

The variable for the name of aSample_ARTE.pdf will be changed to aSample_DIGITAL.ai

Have fun

Silly-V
Legend
January 28, 2015

Oh yea, that $ means the match will be at the end of the string, so my assessment was wrong, pixxxel speaks the truth though.

Silly-V
Legend
January 27, 2015

>> It looks like they can save a .ait with just a document.saveAs(), as long as the file there has the .ait extension.

Oops, I thought you had pasted a previously working example.

The part with the backslashes is a regular expression, which this website regexpal.com is a good playground for, basically the person who used this snipped was taking a part of the filename string from the active document, and replacing it with other stuff to name the resulting .ait with.

I pasted ARTE\..{2,4}$ into the top window of regexpal.com and typed some stuff into the bottom part for testing:

it matched one of the many possibilities, including this one: ARTE.G1

Now, if you imagine their art file was called ARTE.G1.ai and the cadNumber to be 8, for example, the replacement via regular expression would yield: FD-SLOW-SS-8.ait

Silly-V
Legend
January 27, 2015

Well, it looks like you can just save an illustrator file, using illustratorSaveOptions, and then go in after-the-fact to rename the file with a '.ait' extension manually with script perhaps.  I just saved an .ai file from the UI and renamed it in my filesystem - now it opens an untitled document when opened.

Larry G. Schneider
Community Expert
Community Expert
January 28, 2015

I think you're right, V. The "t" in the name prompts the opening of an untitled version of the file.