Adobe 23101335 Scripting Guide - Page 51

appRef.ActiveDocument = appRef.DocumentsMy Document, the Photoshop UI.

Page 51 highlights

Scripting Photoshop 3 The Application object In Visual Basic or VBScript, you create and use a reference to the Application. Typically, you would write: Set appRef = CreateObject("Photoshop.Application") If using VB, this can also be done by writing: Set appRef = New Photoshop.Application In JavaScript, there is no application object and therefore, all properties and methods of the application are accessible without any qualification. To get the active Photoshop document, write: var docRef = 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. AS: set docRef to current document VB: Set docRef = appRef.ActiveDocument JS: docRef = activeDocument; You can also switch back and forth between documents by setting the active document. AS: set current document to document "My Document" VB: appRef.ActiveDocument = appRef.Documents("My Document") JS: activeDocument = documents["My Document"]; Application preferences The application object contains a property for Photoshop preferences. The preferences property is itself an object and has many properties. The name of the preferences object for the three languages is the following: AS: settings VB: Preferences JS: preferences The properties in the preferences object correlate to the preferences found by displaying the Photoshop "Preferences" dialog in the user interface (select the "Edit > Preferences" menu in the Photoshop UI). Photoshop 7.0 Scripting Guide 51

  • 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

Photoshop 7.0 Scripting Guide
51
Scripting Photoshop
The Application object
3
In Visual Basic or VBScript, you create and use a reference to the Application. Typically, you
would write:
Set appRef = CreateObject("Photoshop.Application")
If using VB, this can also be done by writing:
Set appRef = New Photoshop.Application
In JavaScript, there is no application object and therefore, all properties and methods of the
application are accessible without any qualification. To get the active Photoshop document,
write:
var docRef = 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.
AS:
set docRef to current document
VB:
Set docRef = appRef.ActiveDocument
JS:
d
ocRef = activeDocument;
You can also switch back and forth between documents by setting the active document.
AS:
set current document to document "My Document"
VB:
appRef.ActiveDocument = appRef.Documents("My Document")
JS:
activeDocument = documents["My Document"];
Application preferences
The application object contains a property for Photoshop preferences. The preferences
property is itself an object and has many properties. The name of the preferences object for the
three languages is the following:
AS:
settings
VB:
Preferences
JS:
preferences
The properties in the preferences object correlate to the preferences found by displaying the
Photoshop “Preferences” dialog in the user interface (select the “Edit > Preferences” menu in
the Photoshop UI).