test

Page 23

CHAPTER 3: Scripting Photoshop

AS

Creating New Objects in a Script

23

To target Photoshop in AppleScript, you must enclosing your script in the following statements: tell application "Adobe Photoshop CS4" ... end tell

NOTE: Because you include all commands in the tell block, there is no need to reference the Application object throughout the script. VBS

In VBScript, do the following to target the application: Dim appRef Set appRef = CreateObject("Photoshop.Application")

JS

In JavaScript, because you do not need to reference an Application object, all properties and methods of the application are accessible without any qualification. You can reference the application as part of the containment hierarchy or leave it out, whichever makes your scripts easier for you to read. To reference the Application object, use the pre-defined global object app, rather than the class name. The following statements are equivalent: var docRef = app.documents[1]

and var docRef=documents[1]

NOTE: Many JavaScript samples throughout this guide do not reference the Application object.

Creating New Objects in a Script To create a new document in the Photoshop 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 following command: ➤

AS:

make

VBS:

Add

JS:

add()

As you can see in the “Photoshop Object Model” on page 11, the Document object contains all other objects except the Application, Notifier, and Preferences objects. Therefore, you must reference the Document object when adding objects other than Document and Notifier objects to your script. (It is not possible to add a new Preferences object.) NOTE: In VBScript and JavaScript, you use the object’s collection name to name the object type. For example, you add a document to the Documents collection; you add an art layer to the art layers collection. See Introduction to Scripting for more information on elements and collections.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.