Adobe photoshop cs 2.0 User Guide

Page of 91
Photoshop CS2
Adobe Photoshop CS2  Scripting Guide
 Scripting basics     31
}
Executing JavaScripts from AS or VBS
You can take advantage of JavaScript’s platform-independence by running scripts from AppleScript or 
VBScript. You can execute either a single JavaScript statement or a complete JavaScript file.
AS
To run a JavaScript from AppleScript, you use the do javascript command. 
The following sample executes a single JavaScript command, which displays an alert box with the text 
alert text.
do javascript "alert('alert text')" 
To pass a JavaScript file, you can create a reference to the file using as alias or to a reference to 
file 
as shown in the following examples
set scriptFile to "applications: scripts: myscript" as alias
do javascript scriptFile
set scriptFile to a reference to file "applications: scripts: myscript" 
do javascript scriptFile
Note:
Refer to an AppleScript language guide or text book for information on referencing a file using 
either as alias or to a reference to file. 
VBS
In VBScript, use the DoJavaScript method to execute a single JavaScript command. 
objApp.DoJavaScript ("alert('alert text')")
To open a JavaScript file, use the DoJavaScriptFile method. The following sample opens a file on the 
D:\\
 drive.
Dim appRef As Photoshop.Application
Set appRef = CreateObject("Photoshop.Application")
appRef.DoJavaScriptFile ("D:\\Scripts\\MosaicTiles.jsx")
Passing AS or VBS Arguments to JavaScript
You can also pass arguments to JavaScript from either AppleScript or VBScript using the with 
arguments/(Arguments)
 parameter of the do javascript/DoJavaScript or 
DoJavaScriptFile
 command or methods. The parameter takes an array to pass any values.
The following examples execute the following JavaScript, which is stored in a file named JSFile.jsx in 
your Applications\Scripts folder:
alert( "You passed " + arguments.length + " arguments" )
for ( i = 0; i < arguments.length; ++i )
{
alert( arguments[i].toString() )
}
AS
tell application "Adobe Photoshop CS2"
make new document
do javascript (alias a path to the JavaScript shown above) ¬
with arguments {1, "test text", (fileApplications:Scripts:JSFile.jsx),¬
current document}