Adobe 23101764 Scripting Guide - Page 68

The Application object

Page 68 highlights

Scripting Photoshop 3 The Application object 3.7.2 Executing one-line JavaScripts You can also execute simple JavaScripts directly without passing a file as shown in the following examples. AS: do javascript "alert('alert text');" VB: objApp.DoJavaScript ("alert('alert text');") 3.8 The Application object AppleScript and Visual Basic scripts can target multiple applications so the first thing you should do in your script is target Photoshop. By using the properties and commands of the Application object, you can work with global Photoshop settings, open documents, execute actions, and exercise other Photoshop functionality. Targeting the Application object To target the Photoshop application in AppleScript, you must use a tell..end tell block. By enclosing your Photoshop commands in the following statement, AppleScript will understand you are targeting Photoshop. tell application "Adobe Photoshop CS" ... end tell In Visual Basic , you create and use a reference to the Application. Typically, you would write: Set appRef = CreateObject("Photoshop.Application") In JavaScript, there is no need for an application object and therefore, all properties and methods of the application are accessible without any qualification. To get the active Photoshop document in JavaScript, write: var docRef = app.activeDocument; Once you have targeted your application, you are ready to work with the properties and commands of the application object. The active document Because "document 1" does not always indicate the front-most document, it's recommended that your scripts set the current or active document before executing any other commands. To do this, use the "current document (ActiveDocument/activeDocument)" property on the application object. Photoshop CS Scripting Guide 64

  • 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
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

Photoshop CS Scripting Guide
64
Scripting Photoshop
The Application object
3
3.7.2
Executing one-line JavaScripts
You can also execute simple JavaScripts directly without passing a
le as shown in the
following examples.
AS:
do javascript "alert('alert text');"
VB:
objApp.DoJavaScript ("alert('alert text');")
3.8 The Application object
AppleScript and Visual Basic scripts can target multiple applications so the
rst thing you
should do in your script is target Photoshop.
By using the properties and commands of the Application object, you can work with global
Photoshop settings, open documents, execute actions, and exercise other Photoshop
functionality.
Targeting the Application object
To target the Photoshop application in AppleScript, you must use a
tell..end tell
block.
By enclosing your Photoshop commands in the following statement, AppleScript will
understand you are targeting Photoshop.
tell application "Adobe Photoshop CS"
end tell
In Visual Basic , you create and use a reference to the Application. Typically, you would write:
Set appRef = CreateObject("Photoshop.Application")
In JavaScript, there is no need for an application object and therefore, all properties and
methods of the application are accessible without any quali
cation. To get the active
Photoshop document in JavaScript, write:
var docRef = app.activeDocument;
Once you have targeted your application, you are ready to work with the properties and
commands of the application object.
The active document
Because “document 1” does not always indicate the front-most document, it’s recommended
that your scripts set the current or active document before executing any other commands. To
do this, use the “current document (
ActiveDocument/activeDocument
)” property on the
application object.