background image

© 2008 Adobe Systems Incorporated. All rights reserved. 

Adobe® Creative Suite® 4 Photoshop® Scripting Guide

Adobe, the Adobe logo, Illustrator, and Photoshop are either registered trademarks or trademarks of Adobe Systems Inc. 
in the United States and/or other countries. Apple and Mac OS are trademarks of Apple Computer, Inc., registered in the 
United States and other countries. Microsoft and Windows are either registered trademarks or trademarks of Microsoft 
Corporation in the United States and other countries. JavaScript 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 owners.

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.

Adobe Systems Inc., 345 Park Avenue, San Jose, California 95110, USA.

Summary of Contents for 65014293 - Photoshop CS4 - Mac

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

Page 2: ...aScript 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 owners 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 ass...

Page 3: ...ath 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 user interface 14 Additional objects 16 Constants 16 Creating a sample Hello World script 17 Creating and running an AppleScript 18 Creating and running a VBScript 19 Creating and running a JavaScri...

Page 4: ...ind 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 contracting and feathering selections 44 Filling a selection 45 Loading and storing selections 45 Working with Channel objects 46 Changing channel types 46 Using the Document Info object 47 Using histo...

Page 5: ...ining 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 Script using ScriptListener 74 Using the Action Manager from JavaScript 75 Using the Action Manager from a VBS Script 76 Running JavaScript based Action Manager code from VBScript 79 Running JavaScript...

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 the scripting interface NOTE Please review the README file shipped with Photoshop for late breaking news sample scripts and information about outstanding issues Conventions in this Guide Code and spe...

Page 7: ...y 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 LayerSets 1 Layers 1 JS app activeDocument layerSets 0 layers 0 Finally tables are sometimes used to organize lists of values specific to each scripting language ...

Page 8: ...uages 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 different filters to selections in an open document These actions can be simple and affect only a single object or they can be complex and affect many objects in a Photoshop document The actions can call ...

Page 9: ...ich 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 Creating and running a VBScript on page 19 and Creating and running a JavaScript on page 19 You can call JavaScript scripts from AppleScript and VBScript scripts See Executing JavaScripts from AS or VBS on ...

Page 10: ...u 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 for execution Only js or jsx files are displayed in the browse dialog When you select a script file it is executed the same way as an installed script Startup scripts On startup Photoshop executes al...

Page 11: ...re 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 contains Document objects A Document object contains an ArtLayers collection a HistoryStates collection a Layers collection a Layersets collection and a Channels collection Through using commands or method...

Page 12: ...e 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 document that allows you to work on one element of an image without disturbing the others Images are typically composed of multiple layers defined by a Layer Set You can change the composition of an image b...

Page 13: ...ds 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 see Working with Channel objects on page 46 Selection class The Selection class is used to specify an area of pixels in the active document or in a selected layer of the active document that you want...

Page 14: ...on 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 Sampler object provides scripting support for the Color Sampler Tool Measurement Scale class The Measurement Scale object provides scripting support for the new Measurement Scale feature that allows you t...

Page 15: ...me 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 clicks an OK button the notifier object tells the script what to do next Choose File Scripts Script Events Manager Preferences The application preference settings Choose Edit Preferences in Windows or...

Page 16: ...perty 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 Throughout this document actual values of enumerations for VBScript are given using the following format newLayerRef Kind 2 2 indicates psLayerKind 2 psTextLayer The before the explanation creates a comme...

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

Page 18: ...and change its contents target Photoshop CS4 tell application Adobe Photoshop CS4 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 set kind of artLayerRef to text layer Get a reference to the text object and set its contents set contents of...

Page 19: ...rs 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 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 Creating and running a JavaScript Follow these steps...

Page 20: ...ef 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 CS4 directory NOTE You must place your JavaScripts in the Presets Scripts folder in order to make the scripts accessible fr...

Page 21: ... Adobe Photoshop CS4 Visual Basic Scripting Reference Adobe Photoshop CS4 JavaScript Scripting Reference In addition you can also access reference material by using the associated object model browser for each language For AppleScript use the AppleScript Script Editor to view the Photoshop AppleScript Dictionary For VBScript use the VBA editor in Microsoft Word or the Visual Basic Object Browser i...

Page 22: ...iew 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 Set 4 On the COM tab find Adobe Photoshop CS4 Object Library Select it 5 Click Add The selected library appears in the Selected Projects and Components portion of the window 6 Click OK 7 Now the Pho...

Page 23: ...aScript 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 types of objects within a document such as a layer channel or path you use the Window menu or choose the New icon on the appropriate palette This section demonstrates how to accomplish these same tas...

Page 24: ...ind out which commands can be used with an object look up the object in the Adobe Photoshop CS4 AppleScript Scripting Reference If an object has valid commands there will be a Valid Commands list at the end of the object description VBS In VBScript you can use the Add method only with the collection name The Add method is not valid with objects other than collection objects Also in VBScript you mu...

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 associated with the JavaScript Documents object but not with the Document object Similarly the ArtLayer object does not have an add method the ArtLayers object does NOTE The Layers collection object do...

Page 26: ...e 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 inches set otherDocRef to make new document with properties width 4 as inches height 6 as inches make docRef the active document set current document to docRef here you would include command statements...

Page 27: ...ers 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 ActiveDocument docRef docRef ActiveLayer docRef Layers 1 Look up the ActiveLayer property on the Document object in the Adobe Photoshop CS4 Visual Basic Scripting Reference or in the Visual Basic Object B...

Page 28: ...hannels theChannels Alternatively select all component channels using the ComponentChannels property of the Document object appRef ActiveDocument ActiveChannels _ appRef ActiveDocument ComponentChannels JS Set the active channels to the first and third channel using a channel array theChannels new Array docRef channels 0 docRef channels 2 docRef activeChannels theChannels Alternatively select all ...

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 CS4 AppleScript Scripting Reference look up the Photo CD open options class or the EPS open objects class In the Adobe Photoshop CS4 Visual Basic Scripting Reference or the Adobe Photoshop CS4 JavaScript Scripting Reference look...

Page 30: ... Set pdfOpenOptionsRef CreateObject Photoshop PDFOpenOptions pdfOpenOptionsRef AntiAlias True pdfOpenOptionsRef Mode 2 psOpenRGB pdfOpenOptionsRef Resolution 72 pdfOpenOptionsRef Page 3 open the file Dim docRef Set docRef appRef Open C PDFFiles MyFile pdf pdfOpenOptionsRef Restore unit setting appRef Preferences RulerUnits originalRulerUnits JS NOTE The ExtendScript File object expects Universal R...

Page 31: ...t 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 installed explicitly Alias PIX Electric Image SGI RGB Wavefront RLA SoftImage The following scripts save a document as a jpeg file AS tell application Adobe Photoshop CS4 make new document set myFile to OS ...

Page 32: ...elate to the Photoshop CS4 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 preferences please refer to Photoshop Help AS You use properties of the settings class to set application preferences in AppleScript The following script sets ruler and type unit settings set ruler un...

Page 33: ... display dialogs to never In the Adobe Photoshop CS4 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary look up the Class application to find the values you can use for the display dialogs property VBS To set dialog preferences you use the DisplayDialogs property of the Application object appRef DisplayDialogs 3 for PsDialogModes 3 psDisplayNoDialogs Note that because Displ...

Page 34: ...s 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 folder using the preferences folder PreferencesFolder preferencesFolder property of the Application object For further information look up the properties of the Application object in the reference m...

Page 35: ...op CS4 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 and bottom trim without left trim and right trim set ruler units of settings to pixel units crop current document bounds 100 200 400 500 angle 45 width 20 height 20 flip canvas docRef direction horiz...

Page 36: ...its 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 The Photoshop object model contains two types of layer objects ArtLayer objects which can contain image contents and are basically equivalent to Layers in the Photoshop application NOTE An ArtLayer ...

Page 37: ...Add 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 command Dim colorObj Set colorObj CreateObject Photoshop SolidColor colorObj RGB Red 255 colorObj RGB Green 0 colorObj RGB Blue 0 Now apply fill to the current selection appRef ActiveDocument Selection...

Page 38: ...wLayerSetRef 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 layerRef app activeDocument layers 0 Create a new LayerSet it will be created at the beginning of the document var newLayerSetRef app activeDocument layerSets add Move the new layer to after the first ...

Page 39: ...ef 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 also duplicate a layer directly into the destination layer set set current document to document My Document set layerSetRef to make new layer set at end of current document duplicate layer Layer 1 of cu...

Page 40: ...in 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 Photoshop Styles palette to a layer Your script can apply styles to an ArtLayer object To apply a style in a script you use the apply layer style ApplyStyle applyStyle command with the style s name as an...

Page 41: ...ext 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 artLayers add newLayerRef kind LayerKind TEXT See Photoshop Object Model on page 11 for information on the relationship between ArtLayer objects and TextItem objects Also look up the following The Kind kind...

Page 42: ...tType 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 property is set to paragraph text To familiarize yourself with this objects properties and commands in the scripting references do the following In the Adobe Photoshop CS4 AppleScript Scripting Refere...

Page 43: ...nce 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 the vertical position on the canvas The origin point in Photoshop that is x axis 0 and y axis 0 is the upper left corner of the screen The opposite corner the lower right is the extreme point of the c...

Page 44: ...or 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 strokeColor cmyk yellow 30 strokeColor cmyk black 0 app activeDocument selection stroke strokeColor 2 StrokeLocation OUTSIDE ColorBlendMode VIVIDLIGHT 75 false Inverting selections You can use the invert Inv...

Page 45: ...ency 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 red 255 fillColor rgb green 0 fillColor rgb blue 0 app activeDocument selection fill fillColor ColorBlendMode VIVIDLIGHT 25 false To fill the current selection with the tenth item in the history sta...

Page 46: ...annel 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 selRef load docRef channels My Channel SelectionType EXTEND See section Understanding Clipboard Interaction on page 54 for examples on how to copy cut and paste selections Working with Channel objects T...

Page 47: ...her types of information properties you can associate with a document look up the following In the Adobe Photoshop CS4 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary look up the properties for the class info object In the Adobe Photoshop CS4 Visual Basic Scripting Reference the Adobe Photoshop CS4 JavaScript Scripting Reference the Visual Basic Object Browser or the Ext...

Page 48: ...utomatically 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 Start Application in the Script Events Manager File Scripts Script Events Manager in the Photoshop application Please refer to Photoshop Help for information on using the Script Events Manager The make ...

Page 49: ...ate 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 have the points and a subpath you can add a new PathItem The following script creates a PathItem object that is a straight line AS line 1 it s a straight line so the coordinates for anchor left and ...

Page 50: ... Set lineSubPathArray 0 CreateObject Photoshop SubPathInfo lineSubPathArray 0 Operation 2 for PsShapeOperation 2 psShapeXOR lineSubPathArray 0 Closed false lineSubPathArray 0 EntireSubPath lineArray create the PathItem object using Add This method takes the SubPathInfo object and returns a PathItem object which is added to the pathItems collection for the document Set myPathItem docRef PathItems A...

Page 51: ...ties 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 this object you first create an instance of a SolidColor object then set appropriate color model properties for the object Once a color model has been assigned to a SolidColor object the SolidColor ...

Page 52: ...olor 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 the following in the Adobe Photoshop CS4 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary In the Objects section the foreground color property of the class application In t...

Page 53: ...AS 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 color To convert a color to a web safe color use the web safe color command on AppleScript and the NearestWebColor nearestWebColor property of the SolidColor object for VBScript and JavaScript AS set my...

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 Also see Executing JavaScripts from AS or VBS on page 10 Understanding Clipboard Interaction The clipboard commands in Photoshop operate on ArtLayer Selection and Document objects The commands can b...

Page 55: ...ument 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 copy to copy all visible layers in the selected area In AppleScript you use the copy merged command For VBScript and JavaScript you use the Copy copy command passing in a value of True true for the opt...

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 should check and set the ruler units to the type appropriate for your script After executing a script the original values of the ruler settings should be restored if changed in the script See Setting r...

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 necessary to first convert the value to a number unit value cannot be used directly in calculations To multiply an inch value write set newValue to inchValue as number 5 NOTE In AppleScript you can ...

Page 58: ... table of the object in the Interface chapter of the Adobe Photoshop CS4 Visual Basic Scripting Reference or use the Visual Basic Object Browser For JavaScript methods look up the method in the Methods table of the object in the Object Reference chapter in the Adobe Photoshop CS4 JavaScript Scripting Reference or use the ExtendScript Object Model Viewer Class object AppleScript properties VBScript...

Page 59: ...oints 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 INCHES app preferences typeUnits TypeUnits PIXELS app preferences pointSize PointType POSTSCRIPT NOTE Remember to reset the unit settings back to the original values at the end of a script See Working...

Page 60: ...be 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 selected text NOTE When you finish the lesson in each of the following sections save the script you have created in the lesson Each lesson builds upon the script created in the previous lesson Script n...

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 Adobe Photoshop CS4 make Photoshop CS4 the active front most application activate create variables for the default settings set theStartRulerUnits to ruler units of settings set theStartTypeUnits to ...

Page 62: ...BS 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 startRulerUnits Dim startTypeUnits Dim docWidthInInches Dim docHeightInInches Dim resolution Dim helloWorldStr Dim appRef Set appRef CreateObject Photoshop Application assign default preferences to save values in ...

Page 63: ...tartDisplayDialogs app displayDialogs change settings app preferences rulerUnits Units INCHES app preferences typeUnits TypeUnits PIXELS app displayDialogs DialogModes NO create and assign variables for document settings docWidthInInches 4 docHeightInInches 2 resolution 72 docName Hello World use the length property of the documents object to find out if any documents are open if none are found ad...

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

Page 65: ...layer 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 layer a text layer newTextLayer Kind 2 newTextLayer TextItem Contents helloWorldStr newTextLayer TextItem Position Array 0 75 1 newTextLayer TextItem Size 36 newTextLayer TextItem Color textColor 2 Run...

Page 66: ...s 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 the following classes in the Adobe Photoshop CS4 JavaScript Scripting Reference or in the ExtendScript Object Model Viewer to see if you understand how you used them in this script SolidColor ArtLayer...

Page 67: ...ocument 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 whose coordinate is the total number of columns in the document divided by 2 NOTE The value of theDocWidthInPixels is the total number of pixels that defines the document s horizontal dimension Column...

Page 68: ...s 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 using the filter command of the wave filter class inherited from the filter options super class filter current layer of theDocRef using wave filter with options class wave filter number of generators 1...

Page 69: ...ayer 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 docWidthInPixels 2 0 _ Array docWidthInPixels 2 docHeightInPixels _ Array 0 docHeightInPixels Array 0 0 use the ApplyWave method of the ArtLayer class to apply the wave of the selected text newTextLay...

Page 70: ...Array 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 selection select selRegion newTextLayer applyWave 1 1 100 5 10 100 100 WaveType SINE UndefinedAreas WRAPAROUND 0 2 Save the script and then open Photoshop and select the script from the Scripts menu c...

Page 71: ...dius 5 deselect theDocRef 2 Choose Run to run the script NOTE Look up the motion blur class in the Adobe Photoshop CS4 AppleScript Scripting Reference or in the Photoshop AppleScript Dictionary to see if you understand how you used it in this script VBS To apply a motionblur filter to HelloWorldDoc 1 Type the following code into the script file HelloWorldDoc just above the statements that restore ...

Page 72: ...nPixels 0 Array docWidthInPixels docHeightInPixels Array docWidthInPixels 2 docHeightInPixels Array docWidthInPixels 2 0 docRef selection select selRegion newTextLayer applyMotionBlur 45 5 docRef selection deselect 2 Save the script and then open Photoshop and select the script from the Scripts menu choose File Script HelloWorldDoc NOTE Look up the ArtLayer class applyMotionBlur method in the Adob...

Page 73: ...creating 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 task or series of tasks in Photoshop ScriptListener creates several files which contain code that represents the actions taken in Photoshop ScriptingListenerJS log containing JavaScript code Scripti...

Page 74: ...on 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 These objects are not available in AppleScript Recording a Script using ScriptListener The section demonstrates how to create a script log file using ScriptListener We will record the actions necess...

Page 75: ...ew 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 desc4 DialogModes NO NOTE ScriptListener separates logged commands with horizontal lines composed of equal signs If this is not the first action recorded in the log you can easily locate the most re...

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 charIDToTypeID Embs var desc7 new ActionDescriptor var id33 charIDToTypeID Angl desc7 putInteger id33 angle var id34 charIDToTypeID Hght desc7 putInteger id34 height var id35 charIDToTypeID Amnt desc7 putIntege...

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 action from ScriptListenerVB log to another file called emboss vbs 3 In the emboss vbs script identify the values that you used with the filter 135 3 and 100 Substitute the filter specification values ...

Page 78: ...Amnt 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 and call the function with the desired parameters For example the following example applies the Emboss filter with angle 75 height 2 and amount 89 Before the script calls the function it needs to ha...

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 from a VBScript 1 Follow steps 1 4 in Using the Action Manager from JavaScript on page 75 You will end up with a file emboss jsx containing the following JavaScript code function emboss angle height a...

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 var id34 charIDToTypeID Hght desc7 putInteger id34 height var id35 charIDToTypeID Amnt desc7 putInteger id35 amount executeAction id32 desc7 2 At the end of the file emboss jsx add the following line o...

Page 81: ...omething 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 CS4 Samples Fish psd executeAction id14 desc5 DialogModes NO 4 The executeAction method runs the action from a script and it needs ...

Page 82: ...id32 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 desc8 new ActionDescriptor var id35 charIDToTypeID Nw var desc9 new ActionDescriptor var id36 charIDToTypeID ClrI var id37 charIDToTypeID MskI var id38 charIDToTypeID MskA desc9 putEnumerated id36 id...

Page 83: ...e 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 our class IDs for Document and Channel respectively 8 You can now use these event and class IDs to set up event notification on the New Document and New Channel events from your scripts In JavaScript ...

Page 84: ...e 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 object kinds of 13 class IDs finding with ScriptListener 81 classes finding 21 clipboard commands 54 collections VBScript indexing 11 Color object in the DOM 16 Color objects applying to text 64 comparing...

Page 85: ...3 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 AppleScript 10 executing from VBScript 10 running 19 support 10 using Action Manager 75 workflow automation sample 60 L layer classes 12 Layer Comp object defined 13 relationship to user interface 15 Layer...

Page 86: ...erences 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 Save options classes 16 saving documents 31 Script Editor using 18 scripting languages example scripts 17 supported 9 ScriptListener finding class IDs 81 finding event IDs 81 installing 73 log files 73 ...

Page 87: ...layers 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 calculations 57 setting 59 special types 56 value usage 57 values 56 working with 56 V value types constants 16 VBScript conventions 6 creating 19 executing JavaScript from 10 running 19 type library 22 using...

Reviews: