Using Subroutines, Handlers And Functions - Adobe PHOTOSHOP CS 2.0 - SCRIPTING GUIDE Manual

Table of Contents

Advertisement

Adobe Photoshop CS2 Scripting Guide
{
/*create a confirm dialog with the text Quit?
and two response buttons
change the value of flag to the selected response*/
flag = confirm("Quit?")
}
//change the value of flag back to false
var flag = false
do
{
flag = confirm("Are you sure?")
}
while (flag == false)

Using Subroutines, Handlers and Functions

Subroutines are scripting modules you can refer to from within your script. They allow you to re-use parts
of scripts.If you find yourself typing or pasting the same lines of code into several different places in a
script, you've identified a good candidate for a subroutine.
Note:
You can pass one or more values to a subroutine or function; you can receive one or more values in return.
For example, you could pass a single measurement value (such as inches) to a function and ask the
function to return the equivalent value in a different measurement system (such as centimeters). Or you
could ask a function to return the geometric center point of an object from its geometric bounds.
The following samples demonstrate simple subroutine syntax, followed by a more complex subroutine
example.
AS
You enclose a handler in the words
Simple Handler
This sample defines a handler named
with the message Hello World.
on helloWorld()
display dialog "Hello World"
end
To call the handler, you simply include it in your script.
tell Application "Photoshop CS2"
helloWorld()
end tell
When the script runs, the handler enacts the statements in the handler definition.
Complex Handler
The following script displays a dialog with the message Are you sure? and two buttons: Yes and No.
set flag to DoConfirm ("Are you sure?")
display dialog flag as string
'create a handler named DoConfirm
Subroutines can also be called handlers, functions, or routines; these terms can have slight
differences in different scripting languages. In VBScript, a function is a subroutine that returns a
value. JavaScript generally uses the term function; AppleScript generally uses the term handler.
Photoshop CS2
and
.
on
end
that, when called from a script, displays a dialog
helloWorld()
Scripting basics
29

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Photoshop cs2

Table of Contents