Adobe 23101764 Scripting Guide - Page 67
Passing arguments to JavaScript
UPC - 718659340025
View all Adobe 23101764 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 67 highlights
Scripting Photoshop 3 Executing JavaScripts from AS or VB 3.7.1 Passing arguments to JavaScript You can also pass arguments to JavaScript from either AppleScript or Visual Basic by using the with arguments (Arguments) parameter. The parameter takes an array to pass any values. For example, save the following JavaScript to a file 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 CS" 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, use the show debugger (ExecutionMode) argument. The values of this argument include: • never (NeverShowDebugger): This option will disable debugging from the JavaScript. Any error that occurs in the JavaScript will result in a JavaScript exception being thrown. Note that you can catch JavaScript exceptions in your script; see the JavaScript Reference Guide for more information on how to handle JavaScript exceptions. When you use this option the JavaScript command "debugger();" will be ignored. • on runtime error (DebuggerOnError): This option will automatically stop the execution of your JavaScript when a runtime error occurs and show the JavaScript debugger. When you use this option the JavaScript command "debugger();" will stop the JavaScript and display the JavaScript debugger. • before running (BeforeRunning): This option will show the JavaScript debugger at the beginning of your JavaScript. When you use this option the JavaScript command "debugger();" will stop the JavaScript and display the JavaScript debugger. Photoshop CS Scripting Guide 63