Adobe 23102480 Scripting Guide - Page 17

Creating and Running a JavaScript, File > Scripts

Page 17 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Photoshop CS3 Scripting Basics 17 appRef.Preferences.RulerUnits = originalRulerUnits 2. Save file as a text file with a .vbs file name extension. 3. Double-click the file in Windows Explorer to run the script. The script opens Photoshop CS3. Creating and Running a JavaScript Follow these steps to create and run a JavaScript that displays the text Hello World! in a Photoshop CS3 document. Because you will be actually using Photoshop CS3 to run your JavaScripts, it is not necessary to include code that opens Photoshop CS3 at the beginning of the script. Note: Adobe has created the Extend Script scripting language to augment JavaScript for use with Photoshop CS3. You can use the Extend Script command #target to target the Photoshop CS3 application and create the ability to open JavaScripts that manipulate Photoshop CS3 from anywhere in your file system. See the "Script UI" chapter of the JavaScript Tools Guide for more information. ➤ 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( 2, 4 ) // 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.

  • 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
Photoshop CS3 Scripting Basics
17
appRef.Preferences.RulerUnits = originalRulerUnits
2.
Save file as a text file with a
.vbs
file name extension.
3.
Double-click the file in Windows Explorer to run the script.
The script opens Photoshop CS3.
Creating and Running a JavaScript
Follow these steps to create and run a JavaScript that displays the text
Hello World!
in a Photoshop CS3
document.
Because you will be actually using Photoshop CS3 to run your JavaScripts, it is not necessary to include
code that opens Photoshop CS3 at the beginning of the script.
Note:
Adobe has created the Extend Script scripting language to augment JavaScript for use with
Photoshop CS3. You can use the Extend Script command
#target
to target the Photoshop CS3
application and create the ability to open JavaScripts that manipulate Photoshop CS3 from
anywhere in your file system. See the “Script UI” chapter of the
JavaScript Tools Guide
for more
information.
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( 2, 4 )
// 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.