CHAPTER 2: Scripting Features Getting the Current Script 12
Getting the Current Script
You can get a reference to the current script using the activeScript property of the application object.
You can use this property to help you locate files and folders relative to the script, as shown in the
following example (from the ActiveScript tutorial script):
var myScript = app.activeScript;
alert("The current script is: " + myScript);
var myParentFolder = File(myScript).parent;
alert("The folder containing the active script is: " + myParentFolder);
When you debug scripts using a script editor, the activeScript property returns an error. Only scripts run
from the Scripts palette appear in the
activeScript property.
When you debug scripts from the ExtendScript Toolkit, using the
activeScript property returns an error.
To avoid this error and create a way of debugging scripts that use the
activeScript property, use the
following error handler (from the GetScriptPath tutorial script):
function myGetScriptPath() {
try{
return app.activeScript;
}
catch(myError){
return File(myError.fileName);
}
}
Script Versioning
InDesign CS5 can run scripts using earlier versions of the InDesign scripting object model. To run an older
script in a newer version of InDesign, you must consider the following:
X Targeting — Scripts must be targeted to the version of the application in which they are being run
(i.e., the current version). The mechanics of targeting are language specific.
userInteractionLevel
This property controls the alerts and dialogs InDesign presents to the user.
When you set this property to
UserInteractionLevels.neverInteract,
InDesign does not display any alerts or dialogs. Set it to
UserInteractionLevels.interactWithAlerts to enable alerts but
disable dialogs. Set it to
interactWithAll to restore the normal display of
alerts and dialogs. The ability to turn off alert displays is very useful when
you are opening documents via script; often, InDesign displays an alert for
missing fonts or linked graphics files. To avoid this alert, set the
user-interaction level to
UserInteractionLevels.neverInteract before
opening the document, then restore user interaction (set the property to
interactWithAll) before completing script execution.
version
The version of the scripting environment in use. For more information, see
“Script Versioning” on page 12
. Note this property is not the same as the
version of the application.
Property Description