Adobe 27510753 Scripting Guide - Page 18

Variables, Value type, What it is, Example, AppleScript, VBScript

Page 18 highlights

10 Scripting Basics Adobe InDesign CS2 Scripting Guide Value type Double (VBScript), fixed or real (AppleScript), floating point (JavaScript) String Array (VBScript, JavaScript) or list (AppleScript) What it is A high-precision number that can contain a decimal point. A series of text characters. Strings appear inside (straight) quotation marks. A list of values (the values can be any type). Example 13.9972 "I am a string" AppleScript: {"0p0", "0p0", "16p4", "20p6"} VBScript: Array("0p0", "0p0", "16p4", "20p6") JavaScript: ["0p0", "0p0", "16p4", "20p6"] Variables Variables are containers for data. A variable might hold a number, a string of text, or a reference to an InDesign object. Variables have names, and you refer to a variable by its name. To put data into a variable, you assign the data to the variable. The file name of the current InDesign publication, the current date and time, and the number of pages in the publication are all examples of data that you can assign to a variable. Why not simply enter the data itself (the publication's name, or the current date and time, or the number of pages in the publication, for example), rather than using variables? Because, if you do, your script will work in only one publication or situation. By using variables, you can write scripts that will work in a wider range of situations. As a script executes, it can assign data to the variables that reflect the current publication and selection (for example), and then make decisions based on the content of the variables. Assigning values or strings to variables is fairly simple, as shown in the following examples. AppleScript VBScript JavaScript set myNumber to 10 set myString to "Hello, World!" myNumber = 10 myString = "Hello, World!" var myNumber = 10; var myString = "Hello, World!"; In AppleScript, you can assign an object reference to a variable as you create the object: set myTextFrame to make text frame with properties(geometric bounds: (0,0,3.5, 4)) or you can fill the variable with a reference to an existing object: tell application "Adobe InDesign CS2" set myTextFrame to first text frame of the first spread of the first document end tell VBScript works in a similar way. For example, to assign a variable as you create a frame (myInDesign in the following line is a reference to the InDesign application object): Set myTextFrame = myInDesign.Documents.Item(1).Spreads.Item(1).TextFrames.Add or to refer to an existing frame: Set myTextFrame = InDesign.Documents.Item(1).Spreads.Item(1).TextFrames.Item(1)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184

10
Scripting Basics
Adobe InDesign CS2 Scripting Guide
Value type
What it is
Example
Double (VBScript),
fixed or real (Apple-
Script), floating point
(JavaScript)
A high-precision number that can con-
tain a decimal point.
13.9972
String
A series of text characters. Strings ap-
pear inside (straight) quotation marks.
"I am a string"
Array (VBScript,
JavaScript)
or list (AppleScript)
A list of values (the values can be any
type).
AppleScript
: {"0p0", "0p0",
"16p4", "20p6"}
VBScript
: Array("0p0", "0p0",
"16p4", "20p6")
JavaScript
: ["0p0", "0p0", "16p4",
"20p6"]
Variables
Variables are containers for data. A variable might hold a number, a string of text, or a reference to an
InDesign object. Variables have names, and you refer to a variable by its name. To put data into a variable, you
assign the data to the variable. The file name of the current InDesign publication, the current date and time,
and the number of pages in the publication are all examples of data that you can assign to a variable.
Why not simply enter the data itself (the publication’s name, or the current date and time, or the number of
pages in the publication, for example), rather than using variables? Because, if you do, your script will work
in only one publication or situation. By using variables, you can write scripts that will work in a wider range
of situations. As a script executes, it can assign data to the variables that reflect the current publication and
selection (for example), and then make decisions based on the content of the variables.
Assigning values or strings to variables is fairly simple, as shown in the following examples.
AppleScript
set myNumber to 10
set myString to "Hello, World!"
VBScript
myNumber = 10
myString = "Hello, World!"
JavaScript
var myNumber = 10;
var myString = "Hello, World!";
In AppleScript, you can assign an object reference to a variable as you create the object:
set myTextFrame to make text frame with properties(geometric bounds: (0,0,3.5, 4))
or you can fill the variable with a reference to an existing object:
tell application "Adobe InDesign CS2"
set myTextFrame to first text frame of the first spread of the first document
end tell
VBScript works in a similar way. For example, to assign a variable as you create a frame (
myInDesign
in the
following line is a reference to the InDesign application object):
Set myTextFrame = myInDesign.Documents.Item(1).Spreads.Item(1).TextFrames.Add
or to refer to an existing frame:
Set myTextFrame = InDesign.Documents.Item(1).Spreads.Item(1).TextFrames.Item(1)