Page 2
The information in this document is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Inc. Adobe Systems Inc. assumes no responsibility or liability for any errors or inaccuracies that may appear in this document. The software described in this document is furnished under license and may only be used or copied in accordance with the terms of such license.
Introduction About this Manual This manual provides an introduction to scripting Adobe® Photoshop® CS5 on Mac OS® and Windows®. Chapter 1 covers the basic conventions used in this manual. Chapter 2 covers a brief overview of scripting, how to execute scripts, and the Photoshop object model.
Page 7
1: Introduction Conventions in this Guide 7 HAPTER In this case, refers to the AppleScript property, refers to the VBScript display dialogs DisplayDialogs property and refers to the JavaScript property. displayDialogs For larger blocks of code, scripting examples are listed on separate lines. layer 1 of layer set 1 of current document appRef.ActiveDocument.LayerSets(1).Layers(1) app.activeDocument.layerSets[0].layers[0]...
➤ For detailed information on Photoshop objects and commands, please use the reference information in the three reference manuals provided with this installation: Adobe Photoshop CS5 AppleScript Scripting Reference, Adobe Photoshop CS5 Visual Basic Scripting Reference, and Adobe Photoshop CS5 JavaScript Scripting Reference.
” ➤ A single script can perform actions that involve multiple applications. For example, depending on the scripting language you are using, you could target both Photoshop and another Adobe Creative ® Suite 5 Application, such as Adobe Illustrator CS5, in the same script.
~/Library/Application Support/Adobe/Startup Scripts CS5/Adobe Photoshop If your script is in this main startup folder, it is also executed by all other Adobe Creative Suite 5 applications at startup. If such a script is meant to be executed only by Photoshop, it must include code such as the following: if( BridgeTalk.appName == "photoshop"...
A document object model (DOM) is an application programming interface (API), which allows you to programmatically access various components of a document (as defined for that application) through a scripting language. For additional information about Adobe object models and the scripting languages that support them, see Introduction to Scripting.
2: Photoshop Scripting Basics Photoshop Object Model 12 HAPTER Photoshop containment hierarchy Application (showing key classes only) Document Notifier Preferences Measure- Layer Document History Color Count Channel ment Selection Comp Info State Sampler Item Scale Path Item Art Layer Layer Set Sub Path Text Item Layer Set...
2: Photoshop Scripting Basics Photoshop Object Model 13 HAPTER is a class that comprises multiple layers. Think of it as a folder on your desktop. Since folders Layer Set can contain other folders, a layer set is recursive. That is, one layer set may call another layer set in the Object Model hierarchy.
2: Photoshop Scripting Basics Photoshop Object Model 14 HAPTER Path Item, Sub Path Item, and Path Point classes class represents information about a drawing object, such as the outline of a shape, or a Path Item curved line. The class is contained in the class, and provides the actual geometry Sub Path Item Path Item...
Page 15
2: Photoshop Scripting Basics Photoshop Object Model 15 HAPTER To create this object without using a Object name Description script Path Item A drawing object, such as the outline of a Choose the path selection or pen tools shape or a straight or curved line and draw a path with the mouse.
Adobe Photoshop CS5 JavaScript Scripting ArtLayer Reference or in the Adobe Photoshop CS5 Visual Basic Scripting Reference. One of the properties of this object is ). The value type for that property contains a link to the constant that define the Kind( kind allowed values for the property.
2: Photoshop Scripting Basics Creating a sample Hello World script 17 HAPTER Creating a sample Hello World script This section demonstrates a very simple script in each of the three scripting languages for Photoshop. Traditionally, the first thing to accomplish in any programming environment is the display of a "Hello World"...
-- Sample script to create a new text item and -- change its contents. --target Photoshop CS5 tell application "Adobe Photoshop CS5" -- 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.
Because you will be actually using Photoshop to run your JavaScripts, it is not necessary to include code that opens Photoshop at the beginning of the script. : Adobe has created the Extend Script scripting language to augment JavaScript for use with Photoshop. You can use the Extend Script command...
Page 20
// Restore original ruler unit setting app.preferences.rulerUnits = originalUnit 2. Save file as a text file with a file name extension in the Presets/Scripts folder in your Adobe .jsx Photoshop CS5 directory. : You must place your JavaScripts in the Presets/Scripts folder in order to make the scripts accessible from the File >...
1. In Script Editor, choose File > Open Dictionary. Script Editor displays an Open Dictionary dialog. 2. Choose Adobe Photoshop CS5, and then click Open. Script Editor opens Photoshop and then displays the Photoshop dictionary, which lists objects as well as the commands, properties and elements associated with each object.
To view the VBS object library in Microsoft Word: 1. Start Word, and then choose Tools > Macro > Visual Basic Editor. 2. Choose Tools > References, and then select the Adobe Photoshop Type Library check box and click 3. Choose View > Object Browser.
Creating New Objects in a Script 23 HAPTER To target Photoshop in AppleScript, you must enclosing your script in the following statements: tell application "Adobe Photoshop CS5" end tell : Because you include all commands in the block, there is no need to reference the tell object throughout the script.
Page 24
“Viewing Photoshop’s AppleScript dictionary” on page ➤ To find out which commands can be used with an object, look up the object in the Adobe Photoshop CS5 AppleScript Scripting Reference. If an object has valid commands, there will be a “Valid Commands”...
Setting the Active Object 25 HAPTER If you look up in the object in the Adobe Photoshop CS5 Visual Basic Scripting Reference or in the Document Visual Basic Object Browser, you will see that there is no method for the object. However, the...
Document activeLayer activeHistoryState Similarly, if you look at in the Adobe Photoshop CS5 AppleScript Scripting Reference, or in the application Photoshop AppleScript Dictionary, you find it has the property of , and so on. current For sample scripts that set active objects, see the following sections.
= docRef docRef.ActiveLayer = docRef.Layers(1) Look up the property on the object in the Adobe Photoshop CS5 Visual Basic ActiveLayer Document Scripting Reference, or in the Visual Basic Object Browser. : You can also use the name of the layer to indicate which layer to use. By default, Photoshop names the layers “Layer 1”, “Layer2”.
3: Scripting Photoshop Opening a Document 28 HAPTER Setting the active channels More than one channel can be active at a time, so the current channels ) property of the object takes an array of channels as a ActiveChannels/activeChannels Document value.
Photo CD open options class. EPS open objects ➤ In the Adobe Photoshop CS5 Visual Basic Scripting Reference, or the Adobe Photoshop CS5 JavaScript Scripting Reference, look up the objects. PhotoCDOpenOptions EPSOpenOptions The following examples demonstrate how to open a generic (multi-page/multi-image) PDF document with the following specifications: ➤...
Page 30
The document’s original shape will change to conform to the height and width properties if the original shape is not twice as wide as it is tall. tell application "Adobe Photoshop CS5" set myFilePath to alias "OS X 10.5.8 US:Users:psauto:Desktop:opal_screen.pdf"...
➤ In the Adobe Photoshop CS5 AppleScript Scripting Reference, look up the class EPS save options ➤ In the Adobe Photoshop CS5 Visual Basic Scripting Reference or in the Adobe Photoshop CS5 JavaScript Scripting Reference look up EPSSaveOptions Save Classes...
= 1 'for PsTypeUnits --> 1 (psPixels) In the Adobe Photoshop CS5 Visual Basic Scripting Reference, or in the Visual Basic Object Browser, look up object to view all of the settings properties you can use. Additionally, look up the...
Application In the Adobe Photoshop CS5 Visual Basic Scripting Reference, or in the Visual Basic Object Browser, look up object property . You’ll see the value type for this property is the...
➣ VBS: Set fontsInstalled = AppRef.Fonts ➣ var fontsInstalled = app.fonts ➤ The amount of unused memory available to Adobe Photoshop, using the free memory property of the object. (FreeMemory/freeMemory) Application ➤ The location of the Preferences folder, using the...
¬ "OS X 10.5.8 US:Applications:Adobe Photoshop CS5:Samples:Ducky.tif" open duckFile set docRef to current document resize image docRef width 4 height 4 resize canvas docRef width 4 height 4 trim docRef basing trim on top left pixel with top trim ¬...
3: Scripting Photoshop Working with the Photoshop Object Model 36 HAPTER 'Crop the document with ' angle=45, width=20,height=20 docRef.Crop Array(100,200,400,500),45,20,20 docRef.FlipCanvas 1 ' psHorizontal 'restore ruler units appRef.Preferences.RulerUnits = startRulerUnits //save original ruler units, then assign it to inches startRulerUnits = app.preferences.rulerUnits app.preferences.rulerUnits = Units.INCHES //get a reference to the file, and open it var fileRef = new File(app.path + "/samples/ducky.tif")
The following examples demonstrate how to create an object filled with red at the beginning of ArtLayer the current document. tell application "Adobe Photoshop CS5" make new document make new art layer at beginning of current document ¬ with properties {name:"MyBlendLayer", blend mode:normal} select all current document fill selection of current document with contents ¬...
Layer Set ArtLayer object in the current document: tell application "Adobe Photoshop CS5" make new document with properties {name:"My Document"} make new art layer at beginning of current document make new layer set after layer 1 of current document...
3: Scripting Photoshop Working with the Photoshop Object Model 39 HAPTER You can use the following syntax to refer to the layers by the names given them by the Application: layer 1 of layer set 1 of current document : Unlike object references in JavaScript or VBScript, AppleScript object reference names do not remain constant.
{name:"L2"} link art layer "L1" of current document with art layer "L2" of ¬ current document Look up the command in the Adobe Photoshop CS5 AppleScript Scripting Reference or in the link Photoshop AppleScript Dictionary. Set layer1Ref = docRef.ArtLayers.Add() Set layer2Ref = docRef.ArtLayers.Add()
Adobe Photoshop Kind/kind TextItem/textItem ArtLayer CS5 Visual Basic Scripting Reference, Adobe Photoshop CS5 JavaScript Scripting Reference, or in the Visual Basic Object Browser and the ExtendScript Object Model Viewer. ➤ properties of the class in the Adobe Photoshop CS5 AppleScript...
➤ In the Adobe Photoshop CS5 Visual Basic Scripting Reference, or in the Visual Basic Object Browser look up the property of the object. To find the properties and methods you can use...
Document selection-object ➤ In the Adobe Photoshop CS5 Visual Basic Scripting Reference, or in the Visual Basic Object Browser, look as a property of the object. Also, look up the as a method of the Selection Document Select object.
3: Scripting Photoshop Working with the Photoshop Object Model 44 HAPTER var docRef = app.documents.add(500, 500) var shapeRef = [ [0,0], [0,100], [100,100], [100,0] docRef.selection.select(shapeRef) Stroking the selection border The following examples use the command of the object to stroke stroke (Stroke/stroke()) Selection the boundaries around the current selection and set the stroke color and width.
3: Scripting Photoshop Working with the Photoshop Object Model 45 HAPTER by five pixels. See section “Setting Application Preferences” on page 32 for examples of how to change ruler units. expand selection of current document by pixels 5 contract selection of current document by pixels 5 feather selection of current document by pixels 5 Dim selRef Set selRef = appRef.ActiveDocument.Selection...
3: Scripting Photoshop Working with the Photoshop Object Model 46 HAPTER examples use the command of the object to store the current store (Store/store()) Selection selection in a channel named and extend the selection with any selection that is currently in My Channel that channel.
For information about other types of information (properties) you can associate with a document, look up the following: ➤ In the Adobe Photoshop CS5 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary, look up the properties for the class info-object ➤...
Add/add notification for. Many event IDs are listed in an Appendix in the Adobe Photoshop CS5 JavaScript Scripting Reference, Adobe Photoshop CS5 Visual Basic Scripting Reference, and Adobe Photoshop CS5 AppleScript Scripting Reference. Some events also operate on several types of objects, and the...
: Notification generally does not take effect on events that occur inside of a script, because these events are embedded with in an event. "AdobeScriptAutomation Scripts" tell application "Adobe Photoshop CS5" delete notifiers end try make new notifier with properties {event:"Opn ", ¬...
Page 50
3: Scripting Photoshop Working with the Photoshop Object Model 50 HAPTER Dim appRef, docRef Dim lineArray(1), lineArray2(1), lineSubPathArray(0), myPathItem Set appRef = CreateObject("Photoshop.Application") ' create a document to work with Set docRef = appRef.Documents.Add(5000, 7000, 72, "Simple Line") 'line #1--it’s a straight line so the coordinates for anchor, left, and 'right for each point have the same coordinates 'First create the array of PathPointInfo objects.
3: Scripting Photoshop Working with color objects 51 HAPTER // Next create a SubPathInfo object, which holds the line array // in its entireSubPath property. var lineSubPathArray = new Array() lineSubPathArray[0] = new SubPathInfo() lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR lineSubPathArray[0].closed = false lineSubPathArray[0].entireSubPath = lineArray //create the path item, using add.
CMYK equivalent. convert color get foreground color convert color foreground color to CMYK Look up the following in the Adobe Photoshop CS5 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary: ➤ In the “Objects” section, the property of the class...
3: Scripting Photoshop Working with Filters 53 HAPTER Look up the following in the Adobe Photoshop CS5 Visual Basic Scripting Reference, or in the Visual Basic Object Browser: ➤ as properties of the object model cmyk SolidColor This example uses the...
5 : In the Adobe Photoshop CS5 Visual Basic Scripting Reference, on in the Visual Basic Object Browser look up the method and other methods of the object whose name begins...
True Look up the method for the objects in the Adobe Photoshop CS5 Visual Copy ArtLayer Selection Basic Scripting Reference, or in the Visual Basic Object Browser docRef.selection.copy(true)
3: Scripting Photoshop Working with Units 56 HAPTER Working with Units Photoshop provides two rulers for documents. Using properties on the settings-object ) object, you can set the measurement units for the rulers in your script. The Preferences/Preferences rulers are: ➤...
3: Scripting Photoshop Working with Units 57 HAPTER The values returned for a Photoshop property that uses units is returned as a value of the current ruler type. Getting the height of the document created above: set docHeight to height of current document returns a value of 5.0, which represents 5 inches based on the current ruler settings.
Page 58
HAPTER To use this table, do one of the following: ➤ Look up the properties of the class in the Adobe Photoshop CS5 AppleScript Scripting Reference, or in the Photoshop AppleScript Dictionary. ➤ Look up the property of the object in the Adobe Photoshop CS5 Visual Basic Scripting Reference, the Adobe Photoshop CS5 JavaScript Scripting Reference, the Visual Basic Object Browser, or the ExtendScript Object Model Viewer.
3: Scripting Photoshop Sample Workflow Automation JavaScripts 60 HAPTER Sample Workflow Automation JavaScripts The following sample workflow automation JavaScripts are provided with Photoshop and demonstrate various kinds of scripting usage. The scripts are located in the folder in your application Presets/Scripts directory.
To work with document preferences: 1. Create and run the following script. See “Creating and running an AppleScript” on page 18 for details. tell application "Adobe Photoshop CS5" --make Photoshop CS5 the active (front-most) application activate --create variables for the default settings...
Page 62
3: Scripting Photoshop Advanced Scripting 62 HAPTER --check to see whether any documents are open --if none are found, create a document --use the default document settings as its properties if (count of documents) is 0 then make new document with properties ¬ {width:theDocWidthInInches, height:theDocHeightInInches,¬...
Page 63
3: Scripting Photoshop Advanced Scripting 63 HAPTER 'restore beginning preferences appRef.Preferences.RulerUnits = startRulerUnits appRef.Preferences.TypeUnits = startTypeUnits appRef.DisplayDialogs = startDisplayDialogs Double click the file name in Windows Explorer to run the script. 2. In Photoshop, choose Edit > Preferences > Units & Rulers to verify that your preferences have been returned to your original settings.
3. After viewing the document in Photoshop, close the document without saving it. : Look up the following classes in the Adobe Photoshop CS5 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary to see if you understand how you used them in this script: ➤...
Page 65
3. After viewing the document in Photoshop, close the document without saving it. : Look up the following classes in the Adobe Photoshop CS5 Visual Basic Scripting Reference, or in the Visual Basic Object Browser to see if you understand how you used them in this script: ➤...
3. After viewing the document in Photoshop, close Photoshop without saving the document. : Look up the following classes in the Adobe Photoshop CS5 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer to see if you understand how you used them in this script: ➤...
3: Scripting Photoshop Advanced Scripting 67 HAPTER ➤ Apply a wave filter to the selection. : The wave is a truncated sine curve. Defining the area of a selection object To define the area of a selection object, we create an array of coordinates, or points specified in pixels within the document.
Page 68
4. Save the script in the Script Editor. : Look up the following classes in the Adobe Photoshop CS5 AppleScript Scripting Reference, or in the Photoshop AppleScript Dictionary to see if you understand how you used them in this script: ➤...
Page 69
3. After viewing the document in Photoshop, close the document without saving it. 4. Save the script. : Look up the following classes in the Adobe Photoshop CS5 Visual Basic Scripting Reference, or in the Visual Basic Object Browser to see if you understand how you used them in this script: ➤...
Page 70
3. After viewing the document in Photoshop, close Photoshop without saving the document. : Look up the following classes in the Adobe Photoshop CS5 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer to see if you understand how you used them in this script: ➤...
2. Choose Run to run the script. : Look up the class in the Adobe Photoshop CS5 AppleScript Scripting Reference, or in the motion blur Photoshop AppleScript Dictionary to see if you understand how you used it in this script: To apply a motionblur filter to HelloWorldDoc: 1.
Page 72
2. Save the script, and then open Photoshop and select the script from the Scripts menu (choose File > Script > HelloWorldDoc). : Look up the class method in the Adobe Photoshop CS5 JavaScript ArtLayer applyMotionBlur() Scripting Reference, or in the ExtendScript Object Model Viewer to see if you understand how you used it in...
“Running JavaScript-based Action Manager code from AppleScript” on page Installing ScriptListener The ScriptListener plug-in is located in the folder. ..\Adobe Photoshop CS5\Scripting\Utilities To install the ScriptListener: 1. Select the file and then choose Edit > Copy. ScriptListener.8li 2. Paste the file copy to the following location: ..\Adobe Photoshop CS5\Plug-Ins\Automate...
Action Manager Scripting Objects 74 HAPTER To uninstall the ScriptListener: 1. Close Photoshop. 2. Verify that a copy of the file still exists in the ScriptListener.8li ..\Adobe Photoshop CS5\ folder. Scripting\Utilities 3. Delete the file from the following location: ScriptListener.8li ..\Adobe Photoshop CS\Plug-Ins\Automate 4.
4: Action Manager Using the Action Manager from JavaScript 75 HAPTER 7. Check for the script log files: ➣ In Windows, the log files are in your desktop. ➣ On Mac OS, the log files are on the desktop. Using the Action Manager from JavaScript The section demonstrates how to use the contents of the log to create your ScriptingListenerJS.log...
4: Action Manager Using the Action Manager from a VBS Script 76 HAPTER 4. Wrap the code in a JavaScript function. In the following example, the function name is emboss function emboss( angle, height, amount ) var id19 = charIDToTypeID( "Embs" ); var desc4 = new ActionDescriptor();...
Page 77
4: Action Manager Using the Action Manager from a VBS Script 77 HAPTER To create a VBScript from the ScriptListener output: 1. Open from the desktop. ScriptingListenerVB.log At the end of the file you will see code similar to the following (although your numbers may be different): DIM objApp SET objApp = CreateObject("Photoshop.Application")
Page 78
4: Action Manager Using the Action Manager from a VBS Script 78 HAPTER 4. Wrap the code in a VBScript function. In the following example, the function name is . The Emboss creation of the Photoshop application object needs to be outside of the function, as we will explain in the next step.
4: Action Manager Running JavaScript-based Action Manager code from VBScript 79 HAPTER Function Emboss( angle, height, amount ) REM Use dialog mode 3 for show no dialogs DIM dialogMode dialogMode = 3 DIM id9 id9 = objApp.CharIDToTypeID( "Embs" ) DIM desc4 SET desc4 = CreateObject( "Photoshop.ActionDescriptor"...
// Call emboss with values provided in the "arguments" collection emboss( arguments[0], arguments[1], arguments[2] ); 3. The following AppleScript code sample opens a document and runs the Emboss filter on it: tell application "Adobe Photoshop CS5" set theFile to alias “Application:Documents:MyFile” open theFile do javascript (file <path to Emboss.jsx>) ¬...
// ======================================================= var id14 = charIDToTypeID( "Opn " ); var desc5 = new ActionDescriptor(); var id15 = charIDToTypeID( "null" ); desc5.putPath( id15, new File( "C:\\Program Files\\Adobe\\Adobe Photoshop CS5\\ Samples\\Fish.psd" ) ); executeAction( id14, desc5, DialogModes.NO ); 4. The method runs the action from a script, and it needs the event ID to identify which executeAction action to take.
Page 82
4: Action Manager Using ScriptListener to find event IDs and class IDs 82 HAPTER // ======================================================= var id17 = charIDToTypeID( "Mk " ); var desc6 = new ActionDescriptor(); var id18 = charIDToTypeID( "Nw " ); var desc7 = new ActionDescriptor(); var id19 = charIDToTypeID( "Md "...
Page 83
4: Action Manager Using ScriptListener to find event IDs and class IDs 83 HAPTER 6. The method for both of these actions takes an argument whose value is defined as executeAction . (See .) This is the event ID for the “New” action. This action also needs to know "Mk "...