Creating a Sample Hello World Adobe photoshop Script


This section demonstrates a very simple script in each of the three scripting languages for Photoshop CS3.Traditionally, the first thing to accomplish in any programming environment is the display of a "HelloWorld" message.




1. Open the Photoshop CS3 application.
2. Create a new Document object.
When we create the document, we will also create a variable named docRef and then assign a
reference to the document as the value of docRef. The document will be 4 inches wide and 2 inches
high.
3. Create an Art Layer object.
In our script, we will create a variable named artLayerRef and then assign a reference to the Art
Layer object as the value of artLayerRef.
4. Define artLayerRef as a text item.
5. Set the contents of the text item to "Hello World".
Note: We will also include comments throughout the scripts. In fact, because this is our first script, we will
use comments to excess.

To create and run your first Photoshop CS3 JavaScript:
1. Type the following script.
Note: Entering comments is optional.
// Hello Word Script
// Remember current unit settings and then set units to
// the value expected by this script
var originalUnit = preferences.rulerUnits
preferences.rulerUnits = Units.INCHES
// Create a new 2x4 inch document and assign it to a variable
var docRef = app.documents.add( 4, 6 )
// Create a new art layer containing text
var artLayerRef = docRef.artLayers.add()
artLayerRef.kind = LayerKind.TEXT
// Set the contents of the text layer.
var textItemRef = artLayerRef.textItem
textItemRef.contents = "Hello, World"
// Release references
docRef = null
artLayerRef = null
textItemRef = null
// Restore original ruler unit setting
app.preferences.rulerUnits = originalUnit
2. Save file as a text file with a .jsx file name extension in the Presets/Scripts folder in your Adobe
Photoshop CS3 directory.
Note: You must place your JavaScripts in the Presets/Scripts folder in order to make the scripts
accessible from the File > Scripts menu in Photoshop CS3. The scripts do not appear on the File
> Scripts menu until you restart the application.
Photoshop CS3
Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 18
Note: Photoshop CS3 also supports JavaScript files that use a .js extension.
3. Do either of the following:
 If Photoshop CS3 is already open, choose File > Scripts > Browse, and then navigate to the Presets
Scripts folder and choose your script.
Start or restart Photoshop CS3, and then choose File > Scripts, and then select your script from the
Scripts menu.