Home / Articles / Adobe Photoshop / Learn How to Script Adobe Photoshop CS2

Learn How to Script Adobe Photoshop CS2

Chapter Description

This chapter demonstrates several techniques for creating scripts to use specifically with Adobe Photoshop CS2. More importantly, you'll learn how to use the Adobe Photoshop CS2 scripting references to find the objects, classes, properties, methods, and even some values (called constants or enumerations) you can use to create JavaScripts for Adobe Photoshop CS2.

Creating new objects in a script

To create a new document in the Adobe Photoshop CS2 application, you select File > New. To create other types of objects within a document, such as a layer, channel, or path, you use the Window menu or choose the New icon on the appropriate palette. This section demonstrates how to accomplish these same tasks in a script.

To create an object in a script, you name the type of object you want to create and then use the add() method.

As you can see in the Adobe Photoshop CS2 Object Model, the Document object contains all other objects except the Application object. Therefore, you must reference the Document object when adding objects other than Document objects to your script.

In JavaScript, you can use the add() method only with the collection name. The add() method is not valid with objects other than collection objects.

The JavaScript statement to create a document is:


and not:


To add an ArtLayer object, you must reference the Document object that will contain the layer.


The add() method is associated with the JavaScript Documents object but not with the Document object (see Part 2 of this book).

Similarly, the ArtLayer object does not have an add() method; the ArtLayers object does.

3. Setting the active object | Next Section Previous Section