Adobe 23101335 Scripting Guide - Page 33

Scripting Photoshop, 3.1 Photoshop scripting guidelines

Page 33 highlights

3 Scripting Photoshop 3.1 Photoshop scripting guidelines Once you are used to thinking of Photoshop as an object oriented environment, as discussed in Chapter two, you are ready to move on to writing scripts for the application. It is important to think of the objects in Photoshop as part of an "object containment hierarchy". The diagram below, read from left to right, illustrates Photoshop's containment hierarchy. The following guidelines will also help save debugging time when running Photoshop scripts. ● Before running scripts make sure Photoshop's Text Tool is not selected and no dialog boxes are displayed to avoid script run-time errors. ● Select documents by name rather than numeric index and set the current document in your script before working on it. Document numbers do not represent their stacking order. See 3.4, "Object references" on page 42 for more information. ● In AppleScript always create your document with a name and later get that document by name. -- get the front-most document set docRef to make new document with properties ¬ { height:pixels 144, width:pixels 144, resolution:50,¬ name:"My Document"} ● When working in VB or JavaScript, store the document reference to a newly-created document to reuse later. ● When running AppleScripts and two documents are open with the same name, both documents will be modified when the name is referenced. For example, the following script would modify the color profile of all open documents named "MyDocument." tell application "Adobe Photoshop 7.0" set color profile kind of document "MyDocument" to none end tell Photoshop 7.0 Scripting Guide 33

  • 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
33
3
Scripting Photoshop
3.1 Photoshop scripting guidelines
Once you are used to thinking of Photoshop as an object oriented environment, as discussed in
Chapter two, you are ready to move on to writing scripts for the application. It is important to
think of the objects in Photoshop as part of an “object containment hierarchy”. The diagram
below, read from left to right, illustrates Photoshop’s containment hierarchy.
The following guidelines will also help save debugging time when running Photoshop scripts.
Before running scripts make sure Photoshop’s Text Tool is not selected and no dialog boxes
are displayed to avoid script run-time errors.
Select documents by name rather than numeric index and set the current document in your
script before working on it. Document numbers do not represent their stacking order. See
3.4, “Object references” on page 42
for more information.
In AppleScript always create your document with a name and later get that document by
name.
-- get the front-most document
set docRef to make new document with properties ¬
{ height:pixels 144, width:pixels 144, resolution:50,¬
name:"My Document"}
When working in VB or JavaScript, store the document reference to a newly-created
document to reuse later.
When running AppleScripts and two documents are open with the same name, both
documents will be modified when the name is referenced. For example, the following
script would modify the color profile of all open documents named “MyDocument.”
tell application "Adobe Photoshop 7.0"
set color profile kind of document "MyDocument" to none
end tell