Adobe photoshop cs 2.0 User Guide

Page of 91
Photoshop CS2
Adobe Photoshop CS2  Scripting Guide
 Scripting Photoshop CS2     76
if (app.documents.length == 0)
app.documents.add(docWidthInInches, docHeightInInches, resolution)
//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 Scripts folder.
3. Open Photoshop CS2 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 CS2, close the document without saving it. 
6. To prepare the script for the next section, comment the statements that restore the beginning 
preferences by adding slashes as follows:
//app.preferences.rulerunits = startRulerUnits
//app.preferences.typeunits = startTypeUnits
7. 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 CS2 is closed.
Open the script file 
HelloWorldDoc
 in your script editor application.
AS
To create and specify details in a text item:
1. Type the following code into the 
HelloWorldDoc
 script immediately before the commented 
statements that restore original preferences. 
--create a variable named theDocRef 
--assign the current (active) document to it
set theDocRef to the current document
--create a variable that contains a color object of the RGB color class
--whose color is red
set theTextColor to {class:RGB color, red:255, green:0, blue:0}
--create a variable for the text layer, create the layer as an art layer object
--and use the kind property of the art layer object to make it a text layer
set theTextLayer to make new art layer in theDocRef with¬
properties {kind:text layer}
--Set the contents, size, position and color of the text layer
set contents of text object of theTextLayer to "Hello, World!"
set size of text object of theTextLayer to 36
set position of text object of theTextLayer to {0.75, 1}