Adobe PHOTOSHOP CS 2.0 - SCRIPTING GUIDE Manual page 18

Table of Contents

Advertisement

Adobe Photoshop CS2 Scripting Guide
Why Use Variables?
There are several reasons for using variables rather than entering values directly in the script.
Variables make your script easier to update or change. For example, if your script creates several 4 x 2
inch documents and later you want to change the documents' size to 4 x 3 inches, you could simply
change the value of the variable
script would be updated automatically.
If you had used the direct value 2 inches to enter the height for each new document, updating the
document sizes would be much more tedious. You would need find and change each statement
throughout the script that creates a document.
Variables make your scripts reusable in a wider variety of situations. As a script executes, it can assign
data to the variables that reflect the state of the current document and selection, and then make
decisions based on the content of the variables.
Data Contained in Variables
The data that a variable contains is the variable's value. To assign a value to a variable, you use an
assignment statement. A variable's value can be a number, a string (a word or phrase or other list of
characters enclosed in quotes), an object reference, a mathematical expression, another variable, or a list
(including collections, elements, and arrays).
See
'Using Operators' on page 25
variables as values. See
Assignment statements require specific syntax in each scripting language. See
and Assigning Values' on page 14
Creating Variables and Assigning Values
This section demonstrates how to create two variables named thisNumber and thisString, and then assign
the following values:
Variable
thisNumber
thisString
Note:
When you assign a string value to a variable, you must enclose the value in straight, double quotes
(""). The quotes tell the script to use the value as it appears without interpreting or processing it. For
example, 2 is a number value; "2" is a string value. The script can add, subtract, or perform other
operations with a number value. It can only display a string value.
AS
In AppleScript, you must both create and assign a value to a variable in a single statement. You can create
a variable using either the
With the
set
second, as in the following example:
set thisNumber to 10
set thisString to "Hello, World"
With the
copy
copy 10 to thisNumber
copy "Hello World" to thisString
docHeight
'Using Object Properties' on page 18
Value
10
"Hello World"
command or the
set
command, you list the variable name (called an identifier in AppleScript) first and the value
command, you list the value first and the identifier second.
Photoshop CS2
from 2 to 3 at the beginning of your script and the entire
for information on using mathematical expressions or other
for details.
command.
copy
Scripting basics
for information about arrays.
'Creating Variables
14

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Photoshop cs2

Table of Contents