Adobe 23101335 Scripting Guide - Page 36

Your first Photoshop script, 3.3.1 AppleScript

Page 36 highlights

Scripting Photoshop 3 Your first Photoshop script 3.3 Your first Photoshop script The traditional first project in any programming language is to display the message "Hello World!" In this section, we'll create a new Photoshop document, then add a text item containing this message with examples in AppleScript, Visual Basic, VBScript and JavaScript. IMPORTANT: Before attempting to run these sample scripts make sure you have properly installed the Scripting Support module for Photoshop. 3.3.1 AppleScript 1. Locate and open Script Editor. 2. Enter the following script. The lines preceded by "--" are comments. They're included to document the operation of the script and it's good style to include them in your own scripts. As you look through the script, you'll see how to create, then address, each object. The AppleScript command tell indicates the object that will receive the next message we send. -- Sample script to create a new text item and change its -- contents. tell application "Adobe Photoshop 7.0" -- Create a new document and art layer. set docRef to make new document with properties ¬ {width:3 as inches, height:2 as inches} set artLayerRef to make new art layer in docRef -- Change the art layer to be a text layer. set kind of artLayerRef to text layer -- Get a reference to the text item and set its contents. set contents of text item of artLayerRef to "Hello, World!" end tell 3. Run the script. Photoshop will create a new document, add a new art layer, change the art layer's type to text and set the text to "Hello, World!" Photoshop 7.0 Scripting Guide 36

  • 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
36
Scripting Photoshop
Your first Photoshop script
3
3.3 Your first Photoshop script
The traditional first project in any programming language is to display the message “Hello
World!” In this section, we’ll create a new Photoshop document, then add a text item
containing this message with examples in AppleScript, Visual Basic, VBScript and JavaScript.
IMPORTANT:
Before attempting to run these sample scripts make sure you have properly
installed the Scripting Support module for Photoshop.
3.3.1 AppleScript
1.
Locate and open Script Editor.
2.
Enter the following script. The lines preceded by “--” are comments. They’re included to
document the operation of the script and it’s good style to include them in your own scripts.
As you look through the script, you’ll see how to create, then address, each object. The
AppleScript command
tell
indicates the object that will receive the next message we
send.
-- Sample script to create a new text item and change its
-- contents.
tell application "Adobe Photoshop 7.0"
-- Create a new document and art layer.
set docRef to make new document with properties ¬
{width:3 as inches, height:2 as inches}
set artLayerRef to make new art layer in docRef
-- Change the art layer to be a text layer.
set kind of artLayerRef to text layer
-- Get a reference to the text item and set its contents.
set contents of text item of artLayerRef to "Hello, World!"
end tell
3.
Run the script. Photoshop will create a new document, add a new art layer, change the art
layer’s type to text and set the text to “Hello, World!”