Adobe InDesign CS4 Scripting Tutorial
Scripting and the InDesign object model
14
Array variables
AppleScript, JavaScript, and VBScript support
arrays
, which is a variable type that is a list of values. In
AppleScript, an array is called a
list
. Examples of defining arrays are shown below:
To refer to an item in an array, refer to the item by its index in the array. The first item in an array in VBScript
and JavaScript is item 0; in AppleScript, item 1. Examples of referring to items in an array are shown below:
N
OTE
:
The Visual Basic
OptionBase
statement can be used to set the first item of an array to item 1. In the
examples in this document, the first item in an array is item 0, not item 1, because that is the default. If you
set
OptionBase
to 1, you must adjust all array references in the sample scripts accordingly.
Arrays can include other arrays, as shown in the following table:
Finding the value type of a variable
Sometimes, your scripts must make decisions based on the value type of an object. For example, if you are
working on a script that operates on a text selection, you might want that script to stop if the type of the
selection is a page item. All the scripting languages allow you to determine the type of a variable.
Apple-
Script
-- Given a variable of unknown type, "myMysteryVariable"...
set myType to class of myMysteryVariable
--myType will be an AppleScript type (e.g., rectangle)
Language
Examples of defining arrays
AppleScript
set myArray to {1, 2, 3, 4}
JavaScript
myArray = [1, 2, 3, 4];
VBScript
myArray = Array(1, 2, 3, 4)
Visual
Basic.NET
myArray = New Double (1, 2, 3, 4)
Language
Examples of referring to an item in an array
AppleScript
set myFirstArrayItem to item 1 of myArray
JavaScript
var myFirstArrayItem = myArray[0];
VBScript
myFirstArrayItem = myArray(0)
Language
Examples
AppleScript
set myArray to {{0, 0}, {72, 72}}
JavaScript
var myArray = [[0,0], [72,72]];
VBScript
myArray = Array(Array(0,0), Array(72, 72))
Visual
Basic.NET
myArray = New Array(New Double(0,0), NewDouble (0,0))