Adobe 65048599 Scripting Guide - Page 23

Creating New Objects in a Script

Page 23 highlights

CHAPTER 3: Scripting Photoshop Creating New Objects in a Script 23 AS To target Photoshop in AppleScript, you must enclosing your script in the following statements: tell application "Adobe Photoshop CS5" ... 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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

C
HAPTER
3: Scripting Photoshop
Creating New Objects in a Script
23
AS
To target Photoshop in AppleScript, you must enclosing your script in the following statements:
tell application "Adobe Photoshop CS5"
...
end tell
N
OTE
:
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]
N
OTE
:
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.)
N
OTE
:
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.