Photoshop CS Scripting Guide
8
2
Scripting basics
2.1 Documents as objects
If you use Photoshop, then you create documents, layers, channels and design elements and
probably think of a Photoshop document as a series of layers and channels — or objects.
Automating Photoshop with scripting requires the same object-oriented type of thinking.
The heart of a scriptable application is the object model. In Photoshop, the object model is
comprised of documents, layers and channels. Each object has its own special properties, and
every object in a Photoshop document has its own identity.
This chapter covers the basic concepts of scripting within this object-oriented environment.
2.2 Object model concepts
The terminology of object-oriented programming can initially be a formidable obstacle to
understanding. “Objects” belong to “classes” and have “properties” you manipulate using
“commands” (AppleScript) or “methods” (Visual Basic and JavaScript). What do these words
mean in this context?
It makes sense to think about objects and their properties as components of an object model.
Imagine that you live in a house that responds to your commands. The house is an object, and
its properties might include the number of rooms, the color of the exterior paint or the date of
its construction.
Your house can also contain other objects within. Each room, for example, is an object in the
house, while each window, door, or appliance is an object inside of the room. And each object
can respond to various commands according to its capabilities.
Now apply this object model concept to Photoshop. The Photoshop application is the house,
its documents are the rooms, and the objects in your documents are the windows and doors.
You can tell Photoshop documents to add and remove objects or manipulate individual
properties like color, size and shape. Actions can also be performed -- windows and doors, for
example, may open and close.
2.2.1 Object classes
Objects with the same properties and behaviors are grouped into “classes.” In the house
example, windows and doors belong to their own classes because they have unique properties.
In Photoshop, every type of object— document, art layer, etc.—belongs to its own class, each
with its own set of properties and behaviors.