Adobe 23102480 Scripting Guide - Page 63

Applying Color to a Text Item, File > Scripts > HelloWorldDoc

Page 63 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Photoshop CS3 63 4. After viewing the document in Photoshop CS3, close the document without saving it. 5. Name the script HelloWorldDoc and save it. JS ➤ To work with document preferences: 1. Create the following script. Note: See 'Creating and Running a JavaScript' on page 17 for details on creating a JavaScript. //create and assign variables for default preferences startRulerUnits = app.preferences.rulerUnits startTypeUnits = app.preferences.typeUnits startDisplayDialogs = app.displayDialogs //change settings app.preferences.rulerUnits = Units.INCHES app.preferences.typeUnits = TypeUnits.PIXELS app.displayDialogs = DialogModes.NO //create and assign variables for document settings docWidthInInches = 4 docHeightInInches = 2 resolution = 72 docName = "Hello World" //use the length property of the documents object to //find out if any documents are open //if none are found, add a document if (app.documents.length == 0) app.documents.add(docWidthInInches, docHeightInInches, resolution, docName) //restore beginning preferences app.preferences.rulerunits = startRulerUnits app.preferences.typeunits = startTypeUnits app.displayDialogs = startDisplayDialogs 2. Name the script HelloWorldDoc.jsx and save it in the Presets/Scripts folder. 3. Open Photoshop CS3 and choose File > Scripts > HelloWorldDoc to run the script. 4. Choose Edit > Preferences > Units & Rulers to verify that your preferences have been returned to your original settings. 5. After viewing the document in Photoshop CS3, close the document without saving it. 6. Save the script. Applying Color to a Text Item In this section, we will add a layer to the HelloWorldDoc script, then change the layer to a text object that displays the text Hello, World! in red. Before you begin, do the following: ● Make sure Photoshop CS3 is closed. ● Open the script file HelloWorldDoc in your script editor application.

  • 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

Photoshop CS3
Adobe Photoshop CS3
Scripting Guide
Scripting Photoshop CS3
63
4.
After viewing the document in Photoshop CS3, close the document without saving it.
5.
Name the script
HelloWorldDoc
and save it.
JS
To work with document preferences:
1.
Create the following script.
Note:
See
‘Creating and Running a JavaScript’ on page 17
for details on creating a JavaScript.
//create and assign variables for default preferences
startRulerUnits = app.preferences.rulerUnits
startTypeUnits = app.preferences.typeUnits
startDisplayDialogs = app.displayDialogs
//change settings
app.preferences.rulerUnits = Units.INCHES
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO
//create and assign variables for document settings
docWidthInInches = 4
docHeightInInches = 2
resolution = 72
docName = “Hello World”
//use the length property of the documents object to
//find out if any documents are open
//if none are found, add a document
if (app.documents.length == 0)
app.documents.add(docWidthInInches, docHeightInInches, resolution, docName)
//restore beginning preferences
app.preferences.rulerunits = startRulerUnits
app.preferences.typeunits = startTypeUnits
app.displayDialogs = startDisplayDialogs
2.
Name the script
HelloWorldDoc.jsx
and save it in the Presets/Scripts folder.
3.
Open Photoshop CS3 and choose
File > Scripts > HelloWorldDoc
to run the script.
4.
Choose
Edit > Preferences > Units & Rulers
to verify that your preferences have been returned to
your original settings.
5.
After viewing the document in Photoshop CS3, close the document without saving it.
6.
Save the script.
Applying Color to a Text Item
In this section, we will add a layer to the
HelloWorldDoc
script, then change the layer to a text object that
displays the text
Hello, World!
in red.
Before you begin, do the following:
Make sure Photoshop CS3 is closed.
Open the script file
HelloWorldDoc
in your script editor application.