Adobe 23101335 Scripting Guide - Page 49

Passing arguments to JavaScript, For Visual Basic, use either the Application's

Page 49 highlights

Scripting Photoshop 3 Executing JavaScripts from AS or VB For Visual Basic, use either the Application's DoJavaScript or DoJavaScriptFile method. DoJavaScript takes a string, which is the JavaScript code to execute. DoJavaScriptFile opens a file that contains the JavaScript code. An example is below: AS: set scriptFile to "myscript" as alias do javascript scriptFile VB: Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application") appRef.DoJavaScriptFile ("D:\\Scripts\\MosaicTiles.js") 3.6.1 Passing arguments to JavaScript You can pass arguments to JavaScript from either AppleScript or Visual Basic by using the with arguments (Arguments) parameter. The parameter takes an array for you to pass any values. For example, save the following JavaScript in a file somewhere on your machine: alert( "You passed " + arguments.length + " arguments" ); for ( i = 0; i < arguments.length; ++i ) { alert( arguments[i].toString() ) } To pass arguments from AppleScript try this: tell application "Adobe Photoshop 7.0" make new document do javascript (alias ) ¬ with arguments {1, "test text", (file ),¬ current document} end tell To do the same thing in VB, write: Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application") appRef.DoJavaScriptFile "C:\scripts-temp\test.js", _ Array(1, "text text", appRef.ActiveDocument) When running JavaScript from AppleScript or Visual Basic you can also control the debugging state. To do this you use the show debugger (ExecutionMode) argument. The values of this argument include: Photoshop 7.0 Scripting Guide 49

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91

Photoshop 7.0 Scripting Guide
49
Scripting Photoshop
Executing JavaScripts from AS or VB
3
For Visual Basic, use either the Application's
DoJavaScript
or
DoJavaScriptFile
method.
DoJavaScript
takes a string, which is the JavaScript code to execute.
DoJavaScriptFile
opens a file that contains the JavaScript code. An example is below:
AS:
set scriptFile to "myscript" as alias
do javascript scriptFile
VB:
Dim appRef As Photoshop.Application
Set appRef = CreateObject("Photoshop.Application")
appRef.DoJavaScriptFile ("D:\\Scripts\\MosaicTiles.js")
3.6.1 Passing arguments to JavaScript
You can pass arguments to JavaScript from either AppleScript or Visual Basic by using the
with arguments (Arguments)
parameter. The parameter takes an array for you to pass
any values.
For example, save the following JavaScript in a file somewhere on your machine:
alert( "You passed " + arguments.length + " arguments" );
for ( i = 0; i < arguments.length; ++i )
{
alert( arguments[i].toString() )
}
To pass arguments from AppleScript try this:
tell application "Adobe Photoshop 7.0"
make new document
do javascript (alias <a path to the JavaScript shown above>) ¬
with arguments {1, "test text", (file <a path to a file>),¬
current document}
end tell
To do the same thing in VB, write:
Dim appRef As Photoshop.Application
Set appRef = CreateObject("Photoshop.Application")
appRef.DoJavaScriptFile "C:\scripts-temp\test.js", _
Array(1, "text text", appRef.ActiveDocument)
When running JavaScript from AppleScript or Visual Basic you can also control the
debugging state. To do this you use the
show debugger (ExecutionMode)
argument. The
values of this argument include: