Running Scripts At Startup; Session And Main Script Execution - Adobe 0046100128056 - InDesign - Mac Manual

Javascript
Table of Contents

Advertisement

C
2: Scripting Features
HAPTER
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).
N
: Scripts run in the session ExtendScript engine when InDesign starts can create objects and
OTE
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

Session and Main Script Execution

InDesign has two ways to run a JavaScript,
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
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
following script fragment:
#targetengine "adobe"
session
session
statement and provide your own ExtendScript engine name, as shown in the
18.
and
. These names correspond to the
main
engine. To set the
Running Scripts at Startup 18
engine as the target of an
session

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs5

Table of Contents