Adobe 65014293 Scripting Guide - Page 18

Creating and running an AppleScript, Introduction to Scripting

Page 18 highlights

CHAPTER 2: Photoshop Scripting Basics Creating a sample Hello World script 18 Creating and running an AppleScript You must open the Apple® Script Editor application in order to complete this procedure. NOTE: The default location for the Script Editor is Applications > AppleScript > Script Editor. To create and run your first Photoshop AppleScript: 1. Enter the following script in the Script Editor: NOTE: The lines preceded by "--" are comments. Entering the comments is optional. -- Sample script to create a new text item and -- change its contents. --target Photoshop CS4 tell application "Adobe Photoshop CS4" -- Create a new document and art layer. set docRef to make new document with properties ¬ {width:4 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 object and set its contents. set contents of text object of artLayerRef to "Hello, World" end tell 2. Click Run to run the script. Photoshop creates a new document, adds a new layer, changes the layer's type to text and sets the text to "Hello, World" NOTE: If you encounter errors, refer to Introduction to Scripting, which has a section on AppleScript debugging.

  • 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

C
HAPTER
2: Photoshop Scripting Basics
Creating a sample Hello World script
18
Creating and running an AppleScript
You must open the Apple
®
Script Editor application in order to complete this procedure.
N
OTE
:
The default location for the Script Editor is
Applications > AppleScript > Script Editor
.
To create and run your first Photoshop AppleScript:
1.
Enter the following script in the Script Editor:
N
OTE
:
The lines preceded by “--” are comments. Entering the comments is optional.
-- Sample script to create a new text item and
-- change its contents.
--target Photoshop CS4
tell application "Adobe Photoshop CS4"
-- Create a new document and art layer.
set docRef to make new document with properties ¬
{width:4 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 object and set its contents.
set contents of text object of artLayerRef to "Hello, World"
end tell
2.
Click
Run
to run the script. Photoshop creates a new document, adds a new layer, changes the layer’s
type to text and sets the text to “Hello, World”
N
OTE
:
If you encounter errors, refer to
Introduction to Scripting
, which has a section on AppleScript
debugging.