Operators; Conditional Statements; Control Structures - Adobe 65024872 - InDesign CS4 - Mac Manual

Scripting guide
Hide thumbs Also See for 65024872 - InDesign CS4 - Mac:
Table of Contents

Advertisement

Adobe InDesign CS4 Scripting Tutorial
JavaScript
//Given a variable of unknown type, "myMysteryVariable"...
myType = myMysteryVariable.constructor.name;
//myType will be a string corresponding to the JavaScript type (e.g., "Rectangle")
VBScript
Rem Given a variable of unknown type, "myMysteryVariable"...
myType = TypeName(myMysteryVariable)
Rem myType will be a string corresponding to the variable type (e.g., "Rectangle")

Operators

Operators use variables or values to perform calculations (addition, subtraction, multiplication, and
division) and return a value. For example:
MyWidth/2
This returns a value equal to half of the content of the variable
You also can use operators to perform comparisons: equal to (
than(
). For example:
<
MyWidth > myHeight
This returns
All the scripting languages provide additional utility operators. In AppleScript and VBScript, the
ampersand (
"Pride " & "and Prejudice"
This returns the following string:
"Pride and Prejudice"
In JavaScript, use the plus sign (
"Pride " + "and Prejudice"
//returns the string: "Pride and Prejudice"

Conditional statements

"If the selected object is a rectangle, set its stroke weight to 12 points. " This is an example of a conditional
statement. Conditional statements make decisions; they give your scripts a way to evaluate something (like
the color of the selected object, the number of pages in the publication, or the date) and act based on the
result. Conditional statements almost always start with
N
: Conditional statements often make logical comparisons. In AppleScript and VBScript, use the equals
OTE
sign (
) to compare objects. In JavaScript, the equals sign assigns a value to a variable; to compare objects,
=
use a double equals sign (

Control structures

If you could talk to InDesign, you might say, "Repeat the following procedure 20 times. " In scripting terms,
this is a control structure. Control structures provide repetitive processes, or loops. The idea of a loop is to
repeat an action over and over, with or without changes between instances (or iterations) of the loop, until
a specific condition is met. Control structures usually start with
JavaScript and VBScript).
(or 1) if
is greater than
true
myWidth
) concatenates (or joins) two strings:
&
) to join the two strings:
+
).
==
Scripting and the InDesign object model 15
.
myWidth
), not equal to(
=
; otherwise,
myHeight
false
.
if
(in AppleScript) or
repeat
), greater than(
), or less
<>
>
(0).
(in
for

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs4

Table of Contents