
Photoshop CS Scripting Guide
22
Scripting basics
Operators
2
2.7 Operators
Operators perform calculations (addition, subtraction, multiplication, and division) on
variables or values and return a result. For example:
docWidth/2
would return a value equal to half of the content of the variable
docWidth
. So if
docWidth
contained the number
20.5,
the value returned would be
10.25
.
You can also use operators to perform comparisons (equal to, not equal to, greater than, or less
than, etc.). Some operators differ between AppleScript, Visual Basic and JavaScript. Consult
your scripting language for operators that may be unique to your OS.
AppleScript and Visual Basic use the ampersand (&) as the concatenation operator to join two
strings.
"Pride " & "and Prejudice."
would return the string “Pride and Prejudice.”
JavaScript uses the “+” operator to concatenate strings.
"Pride" + " and Prejudice"
would return the string “Pride and Prejudice.”
2.8 Commands and methods
Commands (AppleScript) or methods (Visual Basic and JavaScript) are what makes things
happen in a script. The type of the object you’re working with determines how you manipulate
it.
AS
In AppleScript, use the
make
command to create new objects, the
set
command to assign
object references to variables and to change object properties, and the
get
command to
retrieve objects and their properties.
VB
In Visual Basic, use the Add method to create new objects, the Set statement to assign object
references to Visual Basic variables or properties and the assignment operator (=) to retrieve
and change object properties.
JS
In JavaScript, use the
add()
method to create new objects, and the assignment operator (=)
to assign both object references and variables.