Adobe 0046100128056 Scripting Guide - Page 21
Saving a document, SaveAsTemplate tutorial script
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 21 highlights
CHAPTER 3: Documents Basic Document Operations 21 Saving a document In the InDesign user interface, you save a file by choosing File > Save, and you save a file to another file name by choosing File > Save As. In InDesign scripting, the save method can do either operation, as shown in the following script fragment (from the SaveDocument tutorial script): //If the active document has been changed since it was last saved, save it. if(app.activeDocument.modified == true){ app.activeDocument.save(); } The save method has two optional parameters: The first (to) specifies the file to save to; the second (stationery) can be set to true to save the document as a template, as shown in the following script fragment (from the SaveDocumentAs tutorial script): //If the active document has not been saved (ever), save it. if(app.activeDocument.saved == false){ //If you do not provide a file name, InDesign displays the Save dialog box. app.activeDocument.save(new File("/c/myTestDocument.indd")); } You can save a document as a template, as shown in the following script fragment (from the SaveAsTemplate tutorial script): //Save the active document as a template. var myFileName; if(app.activeDocument.saved == true){ //Convert the file name to a string. myFileName = app.activeDocument.fullName + ""; //If the file name contains the extension ".indd", change it to ".indt". if(myFileName.indexOf(".indd")!=-1){ var myRegularExpression = /.indd/gi myFileName = myFileName.replace(myRegularExpression, ".indt"); } } //If the document has not been saved, then give it a default file name/file path. else{ myFileName = "/c/myTestDocument.indt"; } app.activeDocument.save(File(myFileName), true); Closing a document The close method closes a document, as shown in the following script fragment (from the CloseDocument tutorial script): app.activeDocument.close(); //Note that you could also use: //app.documents.item(0).close(); The close method can take up to two optional parameters, as shown in the following script fragment (from the CloseWithParameters tutorial script):