Using the do script Method. Adobe InDesign CS6
Werbung
Werbung
C HAPTER 2: Scripting Features Using the do script Method 14
For example, to change the version of the scripting object model to CS5 (7.0):
--Set to 7.0 scripting object model set version of script preferences to 7.0
Using the do script Method
The do script
method gives a script a way to execute another script. The script can be a string of valid scripting code or a file on disk. The script can be in the same scripting language as the current script or another scripting language. The available languages vary by platform: on Mac OS
®
, you can run
AppleScript or JavaScript; on Windows
®
, VBScript or JavaScript.
The do script
method has many possible uses:
Running a script in another language that provides a feature missing in your main scripting language.
For example, VBScript lacks the ability to display a file or folder browser, which JavaScript has.
AppleScript can be very slow to compute trigonometric functions (sine and cosine), but JavaScript performs these calculations rapidly. JavaScript does not have a way to query Microsoft
®
Excel for the contents of a specific spreadsheet cell, but both AppleScript and VBScript have this capability. In all these examples, the do script
method can execute a snippet of scripting code in another language, to overcome a limitation of the language used for the body of the script.
Creating a script “on the fly.” Your script can create a script (as a string) during its execution, which it can then execute using the do script method. This is a great way to create a custom dialog or panel based on the contents of the selection or the attributes of objects the script creates.
Embedding scripts in objects. Scripts can use the do script method to run scripts that were saved as strings in the label
property of objects. Using this technique, an object can contain a script that controls its layout properties or updates its content according to certain parameters. Scripts also can be embedded in XML elements as an attribute of the element or as the contents of an element. See
“Running Scripts at Startup” on page 18
.
Sending parameters to do script
To send a parameter to a script executed by do script
, use the following form (from the
DoScriptParameters tutorial script): tell application "Adobe InDesign CS6"
--Create a list of parameters.
set myParameters to {"Hello from do script", "Your message here."}
--Create a JavaScript as a string.
set myJavaScript to "alert(\"First argument: \" + arguments[0] +
\"\\rSecond argument: \" + arguments[1])"
--Run the JavaScript using the do script command.
do script myJavaScript language javascript with arguments myParameters
--Create an AppleScript as a string.
set myAppleScript to "tell application \"Adobe InDesign CS6\"" & return set myAppleScript to myAppleScript & "display dialog (\"First argument: \" & item 1 of arguments & return & \"Second argument: \" & item 2 of arguments)" & return set myAppleScript to myAppleScript & "end tell"
--Run the AppleScript using the do script command.
do script myAppleScript language applescript language with arguments myParameters end tell
Herunterladen
Werbung