Photoshop CS Scripting Guide
55
Scripting Photoshop
Object references
3
This code snippet removes the "marching ants" and blurs the text on the right side of the
document.
3.5 Object references
The remainder of this document elaborates on the scripting concepts and Object Model
components described in the previous code samples.
The objects in your scripts are arranged in a hierarchy that mirrors the Object Model. When
you send a command to a Photoshop object, you need to make sure you send the message to
the right object. The way you identify an object varies with the scripting language used.
3.5.1 AppleScript
AppleScript uses object references to identify the target object for commands. When working
with Photoshop you can identify each item in an object reference using either index or name
form. For example, if you have a single document, named “My Document”, open, you could
target the document’s first layer, named “Cloud Layer” with either line:
layer 1 of document 1
or
layer "cloud layer" of document "My Document"
N
O T E
:
When scripting Phothshop a document's index is not always the same as its stacking
order in the user interface. It is possible for
document 1
to not be the front-most
document. For this reason Photoshop will always return object references identifying
documents by name. It is recommended that you always use the name form when
identifying documents in your scripts.
An object's index or name also may change as a result of manipulating other objects. For
example, when a new art layer is created in the document, it will become the first layer, and the
layer that was previously the first layer is now the 2nd layer. Therefore, any references made to
layer 1 of current document will now refer to the new layer.
Consider the following sample script:
1.
tell application "Adobe Photoshop CS"
2.
activate