background image

C

HAPTER

 4: Action Manager

Using ScriptListener to find event IDs and class IDs

     81

Using ScriptListener to find event IDs and class IDs

The section demonstrates how to use ScriptListener to determine event IDs and class IDs for actions taken 
by Photoshop. These event and class IDs are used to set up notification using the 

Notifier class

.

You can determine the event ID for any recordable action by using ScriptListener. Simply install the 
ScriptListener plug in, as described in 

“Installing ScriptListener” on page 73

. Then execute the action you 

want to find the event ID for. The event is logged in the Script Listener log file. (See 

“The ScriptListener 

Plug-In” on page 73

) If the event applies to several different classes of objects, the class ID is also logged in 

the log file.

The following examples show how to find the event ID for the “Open Document” event, and the event and 
class IDs for the “New” event, which applies to several different classes.

Finding the event ID for the “Open Document” event

1.

Make sure that the ScriptListener plug in is installed.

2.

Open Photoshop, then open a document.

3.

Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log 
file. In the JavaScript version of the file, you will see code that looks something like this at the end of 
the file, everything below the row of equal signs the log of the last action taken:

// =======================================================
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 

executeAction

 method runs the action from a script, and it needs the event ID to identify which 

action to take. The first argument, in this case 

id14

, provides the event ID to the method. You can see 

the variable 

id14

 defined several lines earlier, and it shows that the event ID for the Open Document 

action is 

"Opn ".

5.

You can now use this event ID to set up event notification on Open Document from your scripts. In 
JavaScript, for example:

var eventFile = new File(app.path +

 

 "/Presets/Scripts/Event Scripts Only/Welcome.jsx")

app.notifiers.add(

 

"Opn ", eventFile)

Finding the event ID and class ID for the “New” event

1.

Make sure that the ScriptListener plug in is installed.

2.

Open Photoshop, then create a new document using File > New.

3.

Next, create a new channel, using the Create New Channel icon on the Channels palette.

4.

Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log 
file. We have recorded two actions, so we are interested in looking at the last two sections in the file 
that are delimited by the rows of equal signs. In the JavaScript log file, you will see code that looks 
something like this:

Summary of Contents for 65048332

Page 1: ...SCRIPTING GUIDE ADOBE PHOTOSHOP CS5...

Page 2: ...Script and all Java related marks are trademarks or registered trademarks of Sun Microsystems Inc in the United States and other countries All other trademarks are the property of their respective own...

Page 3: ...th Item Sub Path Item and Path Point classes 14 Preferences class 14 Notifier class 14 Count Item class 14 Color Sampler class 14 Measurement Scale class 14 The containment hierarchy and the Photoshop...

Page 4: ...nd 41 Adding and manipulating text in a Text Item object 42 Working with Selection objects 42 Creating and defining a selection 43 Stroking the selection border 44 Inverting selections 44 Expanding co...

Page 5: ...ning the area of a selection object 67 Applying a MotionBlur filter 71 4 Action Manager 73 The ScriptListener Plug In 73 Installing ScriptListener 73 Action Manager Scripting Objects 74 Recording a Sc...

Page 6: ...Script Object Model Viewer see the JavaScript Tools Guide Chapter 4 covers the Action Manager which allows you to write scripts that target Photoshop functionality that is not otherwise accessible in...

Page 7: ...and displayDialogs refers to the JavaScript property For larger blocks of code scripting examples are listed on separate lines AS layer 1 of layer set 1 of current document VBS appRef ActiveDocument...

Page 8: ...ages See Viewing Photoshop Objects Commands and Methods on page 21 Scripting Overview A script is a series of commands that tells Photoshop to perform a set of specified actions such as applying diffe...

Page 9: ...ch scripting language to use and for additional information about using these languages with Adobe applications see Introduction to Scripting See Creating and running an AppleScript on page 18 Creatin...

Page 10: ...can also use Browse to select scripts installed in the Scripts folder after the application was last launched Selecting Browse displays a file browser dialog which allows you to select a script file...

Page 11: ...e identified partially by the objects that contain them In Photoshop the Application object sits at the top of the hierarchy Applications contain a Documents collection The Documents collection contai...

Page 12: ...34 Layer classes Photoshop has two types of layers an Art Layer that can contain image contents and a Layer Set that can contain zero or more art layers An Art Layer is a layer class within a documen...

Page 13: ...s of a Channel object you can create delete and duplicate channels You can also retrieve a channel s histogram change its kind or change the current channel selection For more information on channels...

Page 14: ...n event For more information on notifiers see Using Notifier objects on page 48 Count Item class The Count Item object provides scripting support for the Count Tool Color Sampler class The Color Sampl...

Page 15: ...e author name the name of the image stored in the file etc Choose File File Info Notifier Notifies a script when an event occurs the event then triggers the script to execute For example when a user c...

Page 16: ...erty For example with the kind property of an Art Layer object you can define only specific kinds that Photoshop allows For general information about constants see Introduction to Scripting NOTE Throu...

Page 17: ...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 sc...

Page 18: ...nd 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 inche...

Page 19: ...s Add artLayerRef Kind 2 Set the contents of the text layer Set textItemRef artLayerRef TextItem textItemRef Contents Hello World Restore unit setting appRef Preferences RulerUnits originalRulerUnits...

Page 20: ...f 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 js...

Page 21: ...Adobe Photoshop CS5 Visual Basic Scripting Reference Adobe Photoshop CS5 JavaScript Scripting Reference In addition you can also access reference material by using the associated object model browser...

Page 22: ...ew the VBS object library in the Visual Basic development environment 1 Start Visual Studio 2005 or Visual Basic 2 Select View Object Browser 3 In the Browse drop down box select Edit Custom Component...

Page 23: ...Script samples throughout this guide do not reference the Application object Creating New Objects in a Script To create a new document in the Photoshop application you select File New To create other...

Page 24: ...nd 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 list at th...

Page 25: ...the Document object that contains the layer and use the add method for the ArtLayers collection using the artLayers property of Document documents 0 artLayers add As with VBScript the add method is as...

Page 26: ...28 Setting the active document The following examples demonstrate how to set the active document AS create 2 documents set docRef to make new document with properties width 4 as inches height 4 as in...

Page 27: ...rs Layer 1 Layer2 etc VBS This example assumes appRef and docRef have been previously defined and assigned to the application object and a document object that contains at least one layer appRef Activ...

Page 28: ...annels theChannels Alternatively select all component channels using the ComponentChannels property of the Document object appRef ActiveDocument ActiveChannels _ appRef ActiveDocument ComponentChannel...

Page 29: ...which options you can set for each of file type look up the properties for the OpenOptions objects that begin with the file format name For example In the Adobe Photoshop CS5 AppleScript Scripting Ref...

Page 30: ...Set pdfOpenOptionsRef CreateObject Photoshop PDFOpenOptions pdfOpenOptionsRef AntiAlias True pdfOpenOptionsRef Mode 2 psOpenRGB pdfOpenOptionsRef Resolution 72 pdfOpenOptionsRef Page 3 open the file D...

Page 31: ...is important to note that the Open and Save formats are not identical See Specifying file formats to open on page 29 for comparison NOTE The following optional formats are available only when install...

Page 32: ...late to the Photoshop CS5 Preferences dialog options which you display by choosing Photoshop Preferences on Mac OS or Edit Preferences in Windows versions of Photoshop For explanations of individual p...

Page 33: ...display dialogs to never In the Adobe Photoshop CS5 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary look up the Class application to find the values you can use for the disp...

Page 34: ...JS var fontsInstalled app fonts The amount of unused memory available to Adobe Photoshop using the free memory FreeMemory freeMemory property of the Application object The location of the Preferences...

Page 35: ...p 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...

Page 36: ...ts Units PIXELS docRef crop new Array 100 200 400 500 45 20 20 docRef flipCanvas Direction HORIZONTAL restore original preferences app preferences rulerUnits startRulerUnits Working with layer objects...

Page 37: ...dd layerObj Name MyBlendLayer layerObj BlendMode 2 psNormalBlend Select all so we can apply a fill to the selection appRef ActiveDocument Selection SelectAll Create a color to be used with the fill co...

Page 38: ...LayerSetRef Move layerRef 4 psPlaceAfter JS make a new document and a layer in the document app documents add app activeDocument artLayers add Get a reference to the first layer in the document var la...

Page 39: ...f to make new layer set at end of current document set newLayer to duplicate layer Layer 1 of current document to end of current document move newLayer to end of layerSetRef In AppleScript you can als...

Page 40: ...n the ExtendScript Object Model Viewer Additionally look up add as a method of the ArtLayers object Applying styles to layers NOTE This procedure corresponds directly to dragging a style from the Phot...

Page 41: ...xt layer AS make new art layer in current document with properties kind text layer VBS set newLayerRef docRef ArtLayers Add newLayerRef Kind 2 2 indicates psTextLayer JS var newLayerRef docRef artLaye...

Page 42: ...Type PARAGRAPHTEXT When a new text object is created its kind property is automatically set to point text The text object properties height width and leading are valid only when the text item s kind p...

Page 43: ...ce your document is a 2 dimensional object you specify coordinates using the x and y axes as follows You use the x axis to specify the horizontal position on the canvas You use the y axis to specify t...

Page 44: ...r CMYK Yellow 30 strokeColor CMYK Black 0 appRef ActiveDocument Selection Stroke strokeColor 5 1 15 75 False JS strokeColor new solidColor strokeColor cmyk cyan 20 strokeColor cmyk magenta 50 strokeCo...

Page 45: ...ncy VBS Set fillColor CreateObject Photoshop SolidColor fillColor RGB Red 255 fillColor RGB Green 0 fillColor RGB Blue 0 selRef Fill fillColor 15 25 False JS var fillColor new SolidColor fillColor rgb...

Page 46: ...nnel load selection of current document from channel My Channel of current document combination type extended VBS selRef Load docRef Channels My Channel 2 PsSelectionType is 2 psExtendSelection JS sel...

Page 47: ...er 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...

Page 48: ...tomatically create a new document when you open the application you could tie a script that creates a Document object to an Open Application event NOTE This type of script corresponds to selecting Sta...

Page 49: ...te an array of PathPointInfo objects which specify the coordinates of the corners or anchor points of your path Then you create an array of SubPathInfo objects to contain the PathPoint arrays Once you...

Page 50: ...Set lineSubPathArray 0 CreateObject Photoshop SubPathInfo lineSubPathArray 0 Operation 2 for PsShapeOperation 2 psShapeXOR lineSubPathArray 0 Closed false lineSubPathArray 0 EntireSubPath lineArray cr...

Page 51: ...ies red blue and green To set a color in this class you indicate values for each of the three properties In VBScript and JavaScript the SolidColor class contains a property for each color model To use...

Page 52: ...lor model gets the foreground color and then uses the convert command of the color class to convert the color to its CMYK equivalent get foreground color convert color foreground color to CMYK Look up...

Page 53: ...S if equal colors foreground color with background color then VBS If appRef ForegroundColor IsEqual appRef BackgroundColor Then JS if app foregroundColor isEqual backgroundColor Getting a Web safe col...

Page 54: ...Manager from a JavaScript to run a filter If you are using AppleScript or VBScript you can run the JavaScript from your script See Action Manager on page 73 for information on using the Action Manager...

Page 55: ...ment var docRef app activeDocument docRef artLayers Background copy var newDocRef app documents add 8 6 72 New Doc newDocRef paste Using the copy merged command method You can also perform a merged co...

Page 56: ...size to 3 inches by 3 inches docRef ResizeImage 3 3 If the ruler units had been set to pixels the document would be 3 pixels by 3 pixels To ensure that your scripts produce the expected results you sh...

Page 57: ...in this way with a corresponding reference to cm or mm They are not supported by the AppleScript terminology Using unit values in calculations To use a unit value in a calculation in Applescript it is...

Page 58: ...table of the object in the Interface chapter of the Adobe Photoshop CS5 Visual Basic Scripting Reference or use the Visual Basic Object Browser For JavaScript methods look up the method in the Methods...

Page 59: ...ints JS In JavaScript rulerUnits and typeUnits are properties of the Preferences object accessed through the Application object s preferences property as shown below app preferences rulerUnits Units I...

Page 60: ...e applied to words In these sections you will also learn how to do the following Select and work with a specific area of a layer by creating a selection object Apply wave and motion blur filters to se...

Page 61: ...the script restores the original preferences AS 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...

Page 62: ...S To work with document preferences 1 Create the following script See Creating and running a VBScript on page 19 for details create variables for default preferences new preferences Dim startRulerUnit...

Page 63: ...artDisplayDialogs app displayDialogs change settings app preferences rulerUnits Units INCHES app preferences typeUnits TypeUnits PIXELS app displayDialogs DialogModes NO create and assign variables fo...

Page 64: ...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 th...

Page 65: ...ayer object using the Add method of the ArtLayers class assign the layer to the variable newTextLayer Set newTextLayer docRef ArtLayers Add use the Kind property of the Art Layers class to make the la...

Page 66: ...menu choose File Script HelloWorldDoc Be patient while Photoshop executes your commands one by one 3 After viewing the document in Photoshop close Photoshop without saving the document NOTE Look up t...

Page 67: ...cument 0 indicates the top row in the document Upper right corner of the selection theDocWidthInPixels 2 0 theDocWidthInPixels 2 indicates the column in the middle of the document that is the column w...

Page 68: ...0 0 replace the document object with the selection object so that the wave is applied only to the selected text select theDocRef region theSelRegion combination type replaced apply the wave filter us...

Page 69: ...yer Rasterize 1 create an array to define the selection property of the Document object define the selected area as an array of points in the document docRef Selection Select Array Array 0 0 _ Array d...

Page 70: ...rray docWidthInPixels 2 docHeightInPixels Array 0 docHeightInPixels Array 0 0 use the select method of the selection object to create an object and give it the selRegion values as coordinates docRef s...

Page 71: ...ius 5 deselect theDocRef 2 Choose Run to run the script NOTE Look up the motion blur class in the Adobe Photoshop CS5 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary to see...

Page 72: ...Pixels 0 Array docWidthInPixels docHeightInPixels Array docWidthInPixels 2 docHeightInPixels Array docWidthInPixels 2 0 docRef selection select selRegion newTextLayer applyMotionBlur 45 5 docRef selec...

Page 73: ...reating Action Manager scripts Leaving ScriptListener installed continuously will not only create large files that occupy memory on your hard drive it can slow Photoshop performance When you perform a...

Page 74: ...n Reference are part of the Action Manager functionality For detailed information about these objects see the appropriate reference manual or use the object browser for the language you are using NOTE...

Page 75: ...w ActionDescriptor var id20 charIDToTypeID Angl desc4 putInteger id20 135 var id21 charIDToTypeID Hght desc4 putInteger id21 3 var id22 charIDToTypeID Amnt desc4 putInteger id22 100 executeAction id19...

Page 76: ...myfile var docRef app open fileRef Call emboss with desired parameters emboss 75 2 89 finish the script include the function in the script file function emboss angle height amount var id32 charIDToTyp...

Page 77: ...equal signs If this is not the first action recorded in the log you can easily locate the most recent action it follows the final equal sign line 2 Copy the VBScript code associated with the emboss ac...

Page 78: ...mnt Call desc4 PutInteger id12 amount Call objApp ExecuteAction id9 desc4 dialogMode End Function 5 To use a VBScript to apply the Emboss filter to a document include the emboss function in the script...

Page 79: ...code from a VBScript using the DoJavaScriptFile method Use the VBscript object browser for more information on the Application DoJavaScriptFile method To execute JavaScript based Action Manager code f...

Page 80: ...jsx containing the following JavaScript code function emboss angle height amount var id32 charIDToTypeID Embs var desc7 new ActionDescriptor var id33 charIDToTypeID Angl desc7 putInteger id33 angle va...

Page 81: ...mething like this at the end of the file everything below the row of equal signs the log of the last action taken var id14 charIDToTypeID Opn var desc5 new ActionDescriptor var id15 charIDToTypeID nul...

Page 82: ...d32 stringIDToTypeID profile desc7 putString id32 sRGB IEC61966 2 1 var id33 charIDToTypeID Dcmn desc6 putObject id18 id33 desc7 executeAction id17 desc6 DialogModes NO var id34 charIDToTypeID Mk var...

Page 83: ...action operates on The second argument to putObject provides us with the class ID that we need In the first action id33 is defined as Dcmn in the second action id45 is defined as Chnl These provide o...

Page 84: ...15 working with 36 C calculations unit values 57 Channel object activating 28 changing type 46 defined 13 relationship to user interface 15 setting the active channel 28 working with 46 Channel objec...

Page 85: ...purging 48 relationship to user interface 15 reverting 48 using 47 history states defined 47 I images changing composition 12 J JavaScript conventions 6 creating 19 executing 10 executing from AppleS...

Page 86: ...rences setting 32 working with 61 Preferences object defined 14 relationship to user interface 15 properties conventions 6 finding 21 R ruler units defined 56 setting 59 value usage 57 values 56 S Sav...

Page 87: ...ayers 41 The 54 type library VBScript 22 type units defined 56 setting 59 typographic conventions 6 U units AppleScript considerations 56 as parameters 58 as properties 57 in arguments 58 in calculati...

Reviews: