Adobe 27510753 Scripting Guide - Page 121
Saving a document, method can do either operation
UPC - 718659445294
View all Adobe 27510753 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 121 highlights
Adobe InDesign CS2 Scripting Guide Working with Documents in JavaScript 113 The close method can take up to two optional parameters: //CloseWithParameters.jsx //An InDesign CS2 JavaScript //Use SaveOptions.yes to save the document,SaveOptions.no to close the //document without saving, or SaveOptions.ask to display a prompt. If //you use SaveOptions.yes, you'll need to provide a reference to a file //to save to in the second parameter (SavingIn). //Note that the file path is provided using the JavaScript URI form //rather than the platform-specific form. // //If the file has not been saved, display a prompt. if(app.activeDocument.saved != true){ app.activeDocument.close(SaveOptions.ask); //Or, to save to a specific file name: //var myFile = File("/c/myTestDocument.indd"); //app.activeDocument.close(SaveOptions.yes, myFile); } else{ //If the file has already been saved, save it. app.activeDocument.close(SaveOptions.yes); } This example closes all open documents without saving them: //CloseAll.jsx //An InDesign CS2 JavaScript //Closes all open documents without saving. for(myCounter = app.documents.length; myCounter > 0; myCounter--){ app.documents.item(myCounter-1).close(SaveOptions.no); } Saving a document In the InDesign user interface, you save a file by choosing Save from the File menu, and you save a file to another file name by choosing Save As. In InDesign scripting, the save method can do either operation: //SaveDocument.jsx //An InDesign CS2 JavaScript //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. //SaveDocumentAs.jsx //An InDesign CS2 JavaScript //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 will display the Save dialog box. app.activeDocument.save(new File("/c/myTestDocument.indd")); } The following example saves a document as a template: //SaveAsTemplate.jsx //An InDesign CS2 JavaScript //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 + "";