Adobe 0046100128056 Scripting Guide - Page 18
Running Scripts at Startup, Session and Main Script Execution
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 18 highlights
CHAPTER 2: Scripting Features Running Scripts at Startup 18 var myDocument = app.documents.add(); myDocument.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.points; myDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.points; var myPage = myDocument.pages.item(0); var myRectangle = myPage.rectangles.add({geometricBounds:[72, 72, 144, 144]}); //Insert a custom label using insertLabel. The first parameter is the //name of the label, the second is the text to add to the label. myRectangle.insertLabel("CustomLabel", "This is some text stored in a custom label."); //Extract the text from the label and display it in an alert. var myString = myRectangle.extractLabel("CustomLabel"); alert("Custom label contained: " + myString); Running Scripts at Startup To run a script when InDesign starts, put the script in the Startup Scripts folder in the Scripts folder (for more information, see "Installing Scripts" in Adobe InDesign CS5 Scripting Tutorial). NOTE: Scripts run in the session ExtendScript engine when InDesign starts can create objects and functions that will be available to other scripts for the duration of the session. For more information, see "Session and Main Script Execution" on page 18. Session and Main Script Execution InDesign has two ways to run a JavaScript, session and main. These names correspond to the ExtendScript "engine" used to run the script. By default, when you run an InDesign JavaScript, the script is interpreted and executed by the "main" ExtendScript engine, which is destroyed when the script completes execution. Script objects created by the script do not persist. Scripts run in the session engine can create objects that persist until you close InDesign. You can refer to these objects from other scripts run in the session engine. To set the session engine as the target of an InDesign JavaScript, add the following line to the start of your script. #targetengine "session" You can create your own persistent ExtendScript interpretation and execution environment. To do this, use the #targetenging statement and provide your own ExtendScript engine name, as shown in the following script fragment: #targetengine "adobe"