Adobe photoshop cs 2.0 User Guide

Page of 91
Photoshop CS2
Adobe Photoshop CS2  Scripting Guide
 Scripting basics     10
Note:
Your scripts place objects in elements or collections even when there is only one object of that type 
in the entire script, that is, only one object in the element or collection.
When you add an object, the object is numbered automatically within its respective element or collection. 
You can identify the object in other script statements by using its element or collection name and assigned 
number. 
Using the house example, when you add a room to your house, your script stores a number that identifies 
the room. If it’s the first room you’ve added, your AppleScript considers the room to be room1; your 
VBScript script or JavaScript considers the room to be room0
Here’s how the scripting languages handle the automatic numbering if you add a second room:
AppleScript considers the new room room1 and renumbers the previously added room so that it 
becomes room2. AppleScript object numbers shift among objects to indicate the object that you 
worked with most recently. See the AppleScript section in 
 for further details on this topic. 
VBScript or JavaScript numbers are static; they don’t shift when you add a new object to the collection. 
Object numbering in VBScript and JavaScript indicates the order in which the objects were added to 
the script. Because the first room you added was considered room0, the next room you add is 
considered room1; if you add a third room, it is labeled room2
When you add an object that is not a room, the numbering starts all over for the new object element or 
collection. For example, if you add a door, your AppleScript considers the door to be door1; your VBScript 
script or JavaScript considers the door door0.
Note:
You can also name objects when you add them. For example, you can name the rooms livingRoom 
and bedRoom. If an object has a name, you can refer to the object in your script either by name or by 
the element/collection name followed by the assigned number. 
Generally, beginning scripters are encouraged to use object names in AppleScript.
In VBScript or JavaScript, you’ll find object numbers very useful. For example, you may have several files in 
which you want to make the background layer white. You can write a script that says "Open all files in this 
folder and change the first layer’s color to white." If you didn’t have the capability of referring to the layers 
by number, you’d need to include in your script the names of all of the background layers in all of the files. 
Chances are, if you created the files using the Photoshop CS2 application rather than a script, the layers 
don’t even have names. 
Indexes or Indices
An object’s number in an element or collection is called an index
Referring to an Object in an Element or Collection
A collection or element name is the plural version of the object type name. For example, an element or 
collection of Document objects is called documents. In JavaScript and VBScript, you can use the collection 
name and the index to refer to an object. The syntax is slightly different in AppleScript. 
The following code samples demonstrate the correct syntax for using an object’s index when referring to 
the object. 
Tip:
Remember that VBScript and JavaScript indices begin with 0. Beginning your count with 0 may seem 
confusing, but as you learn about scripting, you’ll find that using 0 gives you added capabilities for 
getting your scripts to do what you want.