Adobe 23101764 Scripting Guide - Page 35

Scripting Photoshop

Page 35 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. The following guidelines will 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.5, "Object references" on page 55 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 CS" set color profile kind of document "MyDocument" to none end tell 3.2 Viewing Photoshop objects, commands and methods This section shows how to view Photoshop's objects, commands and properties in AppleScript and Visual Basic editors. JavaScript is a cross-platform language and therefore does not include a native script editor. Photoshop CS Scripting Guide 31

  • 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
31
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.
The following guidelines will 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.5, “Object references” on page 55
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 modi
ed when the name is referenced. For example, the following script
would modify the color pro
le of all open documents named “MyDocument.”
tell application "Adobe Photoshop CS"
set color profile kind of document "MyDocument" to none
end tell
3.2 Viewing Photoshop objects, commands and methods
This section shows how to view Photoshop’s objects, commands and properties in AppleScript
and Visual Basic editors. JavaScript is a cross-platform language and therefore does not
include a native script editor.