background image

Photoshop CS2

Adobe Photoshop CS2  Scripting Guide

 Scripting Photoshop CS2     53

current document

Look up the 

link

 command in the 

Adobe Photoshop CS2 AppleScript Scripting Reference

VBS

Set layer1Ref = docRef.ArtLayers.Add()
Set layer2Ref = docRef.ArtLayers.Add()
layer1Ref.Link layer2Ref.Layer

Look up 

Link

 in the Methods table of the 

ArtLayer

 object in the 

Adobe Photoshop CS2 Visual Basic 

Scripting Reference

. Additionally, look up 

Add

 in the Methods table of the 

ArtLayers

 object. 

JS

var layerRef1 = docRef.artLayers.add()
var layerRef2 = docRef.artLayers.add()
layerRef1.link(layerRef2)

Look up 

link()

 in the Methods table of the 

ArtLayer

 object in the 

Adobe Photoshop CS2 JavaScript 

Scripting Reference

. Additionally, look up 

add()

 in the Methods table of the 

ArtLayers

 object.

Applying Styles to Layers

Note:

This procedure corresponds directly to dragging a style from the Photoshop CS2 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/method with the style’s name as an argument enclosed in 

straight double quotes. 

Note:

The layer style names are case sensitive.

Please refer to Photoshop CS2 Help for a list of styles and for more information about styles and the Styles 
palette.

The following examples set the Puzzle layer style to the layer named “L1.” 

AS

apply layer style art layer "L1" of current document using ¬

"Puzzle (Image)"

Look up the

 apply layer style

 command in the “Commands” chapter of the 

Adobe Photoshop CS2 

AppleScript Scripting Reference

.

VBS

docRef.ArtLayers("L1").ApplyStyle "Puzzle (Image)"

Look up 

ApplyStyle

 in the Methods table of the 

ArtLayer 

object in the 

Adobe Photoshop CS2 Visual Basic 

Scripting Reference

.

JS

docRef.artLayers["L1"].applyStyle("Puzzle (Image)")

Look up 

applyStyle()

 in the Methods table of the 

ArtLayer 

object in the 

Adobe Photoshop CS2 

JavaScript Scripting Reference

.

Summary of Contents for PHOTOSHOP CS 2.0 - SCRIPTING GUIDE

Page 1: ...bbc Adobe Photoshop cs 2 Scripting Guide ...

Page 2: ...Mac and Macintosh 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 UNIX is a regis...

Page 3: ...ript Lines 21 Creating a Sample Hello World Script 21 Using Operators 25 Using Conditional Statements 26 Using Subroutines Handlers and Functions 29 Executing JavaScripts from AS or VBS 31 Passing AS or VBS Arguments to JavaScript 31 Testing and Troubleshooting 32 Bibliography 34 3 Scripting Photoshop CS2 36 Viewing Photoshop CS2 Objects Commands and Methods 36 Targeting and Referencing the Applic...

Page 4: ...Adobe Illustrator CS2 Visual Basic Scripting Reference Contents iv Sample Workflow Automation JavaScripts 71 Advanced Scripting 72 Index 85 ...

Page 5: ... late breaking news sample scripts and information about outstanding issues Conventions in this guide Code and specific language samples appear in monospaced courier font app documents add Several conventions are used when referring to AppleScript VBScript and JavaScript Please note the following shortcut notations AS stands for AppleScript VBS stands for VBScript JS stands for JavaScript The term...

Page 6: ...pulation are anything but creative Scripting helps creative professionals save time by automating repetitive production tasks such as resizing or reformatting documents Any repetitive task is a good candidate for a script Once you can identify the steps and conditions involved in performing the task you re ready to write a script to take care of it Why use scripts instead of Actions If you ve used...

Page 7: ... you can install it as well from your system software CD ROM Note As your scripts become more complex you may want to add debugging and productivity features not found in the Script Editor There are many third party script editors that can write and debug Apple Scripts For details check http www apple com applescript For more information on the AppleScript scripting environment see Viewing Photosh...

Page 8: ... or VBS on page 31 for more information Note You can use other scripting languages although they are not documented in this manual On Mac OS you can use any language that allows you to send Apple events On Windows you can use any OLE Automation aware language Legacy OLE Automation scripting Photoshop CS2 supports legacy Automation scripting as long as you modify the way that you refer to the Photo...

Page 9: ... a script with similar capability on Windows using VBScript as the scripting language New Features The scripting interface now allows you to do any of the following Specify Camera Raw options when opening a document Optimize documents for the Web Create and format contact sheets Specify options for the Batch command Apply the Lens Blur filter Automatically run scripts when specified events occur F...

Page 10: ...nipulate objects What are objects in the context of a scripting language When you use Photoshop CS2 you create documents layers channels and design elements and you can work with a specific area of an image by selecting the area These things are objects The Photoshop CS2 application is also an object Each type of object has its own properties and commands AppleScript or methods VBScript and JavaSc...

Page 11: ...d JavaScript are different In this guide you will learn basic scripting concepts that these languages share You will also learn some of the syntax that is specific to each language Object Model Concepts In a script statement you refer to an object based on where the object is located in an object model An object model is simply an arrangement of objects The arrangement is called a containment hier...

Page 12: ...n a hierarchy similar to a family tree with the house on top rooms at the next level and the windows and doors branching from the rooms Applying the Concept to Photoshop CS2 Now apply this object model concept to Photoshop CS2 The Photoshop CS2 application is the house its documents are the rooms and the layers layersets channels and selected areas in your documents are the windows doors ceilings ...

Page 13: ...such as the outline of a shape or a straight or curved line Choose the path selection or pen tools and draw a path with the mouse Channel Pixel information about an image s color Choose Window Channels Art Layer A layer class within a document that allows you to work on one element of an image without affecting other elements in the image Choose Layer New Layer or Window Layers Layer Set A collect...

Page 14: ...on For example if you add a door your AppleScript considers the door to be door1 your VBScript script or JavaScript considers the door door0 Note You can also name objects when you add them For example you can name the rooms livingRoom and bedRoom If an object has a name you can refer to the object in your script either by name or by the element collection name followed by the assigned number Gene...

Page 15: ...cts by name VBS In VBScript you use the collection name followed by the index enclosed in parentheses There is no space between the collection name and the parentheses Documents 1 JS In JavaScript the collection name is followed by the index in square brackets with no space between the object name and the brackets documents 0 Object References Because scripts use a containment hierarchy you can th...

Page 16: ...ipt to perform tasks or obtain results For example you could use the open Open open command method to open a specified file Note You can use only the methods or commands associated with that object type For example you can use the open Open open command method on a Document object but not on a Selection object which obviously cannot be opened Before using a command on an AppleScript object look up...

Page 17: ...dd method to add a bitmap document named myDocument that is 4000 pixels wide and 5000 pixels tall and has a resolution of 72 pixels per inch Note Even though the Document object in the following script statements is given a name myDocument you use the object collection name when you add the object See Referring to an Object in an Element or Collection on page 10 for more information on object coll...

Page 18: ...ence a mathematical expression another variable or a list including collections elements and arrays See Using Operators on page 25 for information on using mathematical expressions or other variables as values See Using Object Properties on page 18 for information about arrays Assignment statements require specific syntax in each scripting language See Creating Variables and Assigning Values on pa...

Page 19: ...thisLayer to art layer 1 of current document AppleScript Value Types You can use the following types of values for variables in your AppleScripts Note For now don t worry about the value types you don t understand VBS To create a variable in VBScript you use the Dim keyword at the beginning of the statement The following statements create the variables thisNumber and thisString Dim thisNumber Dim ...

Page 20: ...qual sign The following example uses Set and the Add method to create the variable thisLayer create a new Art Layer object and then assign the new Art Layer object as the value of thisLayer Dim thisLayer Set thisLayer AppRef Documents 0 ArtLayers Add The next example uses Set to assign an existing Art Layer object in this case the third Art Layer object added to the script as the value of thisLaye...

Page 21: ...e descriptive names for your variables such as firstPage or corporateLogo rather than names only you would understand and that you might not recognize when you look at your Object Properties and methods belonging to an object or array activeDocument Documents 1 ArtLayers 2 String A series of text characters Strings appear inside straight quotation marks Hello 123 Main St Value Type What It Is Exam...

Page 22: ... use the kind property of the ArtLayer object to make the layer a text layer AS You can specify properties using with properties at the end of the statement and enclosing the properties in brackets Within the brackets you name the property and then type a colon and the property definition after the colon as in the following sample make new art layer with properties kind text VBS In VBScript you us...

Page 23: ... can use the same property with different constant values The constant values for the Channel object s kind property are different than the constant values for the Art Layer object s kind property Understanding Object Classes and Inheritance In Photoshop CS2 every type of object document layer etc belongs to its own class each with its own set of properties and behaviors Object classes may also in...

Page 24: ...include all the components you planned for your script Unless you are an experienced programmer you can review your script by reading through the comments more easily than you can by reading the code Help others understand your script It s possible that other people in your organization will need to use update or debug your script Comment Syntax You can create the following types of comments Singl...

Page 25: ...ng Long Script Lines In some cases individual script lines are too long to fit on a single line in your script editor window AS AppleScript uses the special character to show that the line continues to the next line This continuation character denotes a soft return in the script Press Option Return to type the character VBS In VBScript use a space followed by an underscore _ JS JavaScript does not...

Page 26: ...rt 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 These steps mirror a specific path in the containment hierarchy as illustrated below Creating and Running an AppleScript You must open Appl...

Page 27: ...u encounter errors see AppleScript Debugging on page 32 Creating and Running a VBScript Follow these steps to create and run a VBScript that displays the text Hello World in a Photoshop CS2 document To create and run your first Photoshop CS2 VBScript 1 Type the following script into a script or text editor Note Entering comments is optional Dim appRef Set appRef CreateObject Photoshop Application ...

Page 28: ...our first Photoshop CS2 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 4x4 inch document and assign it to a variable var docRef app documents add 4 4 Create a new art layer contai...

Page 29: ...e the examples use the following variables thisNumber 10 thisString Pride Comparison Operators You can use a different type of operator to perform comparisons such as equal to not equal to greater than or less than These are called comparison operators Consult a scripting language guide such as the guides listed in this document s Bibliography on page 34 for information on comparison operators Ope...

Page 30: ... CS2 documents are open end if end tell VBS create a variable named docCount for the document count open Photoshop Dim docCount As long Dim appRef As New Photoshop CS2 Application use the count property of the Documents collection object to count the number of open documents docCount appRef Documents Count If docCount 0 Then Alert No Photoshop CS2 documents are open End If JS create a variable nam...

Page 31: ...s if i is equal to or more than 4 stop and don t do anything else with this loop i i 1 After executing the statement in the brackets add 1 to the value of i Note The equation i i 1 can be abbreviated to i More Complex Loops A more complicated type of loop includes conditional logic so that it performs a task while or until some condition is true Conditional statements in a script can include the w...

Page 32: ...lag to button returned of display dialog Quit buttons OK Cancel OK end repeat change the value of flag back to false for the new loop set flag to false create the new loop repeat while flag false set flag to button returned of display dialog Are you sure buttons OK Cancel Cancel end repeat VBS create a variable named flag of type Boolean and set its value to False Dim flag As Boolean flag False cr...

Page 33: ...one or more values to a subroutine or function you can receive one or more values in return For example you could pass a single measurement value such as inches to a function and ask the function to return the equivalent value in a different measurement system such as centimeters Or you could ask a function to return the geometric center point of an object from its geometric bounds The following s...

Page 34: ...orm with one command button When a user clicks the button a dialog appears with the message Are you sure and two buttons Yes and No When the user clicks a button another dialog appears that displays the Boolean value of the clicked button Yes True No False create a subroutine that calls the function DoConfirm and assigns it to the variable named Result Private Sub CommandButton1_Click Result DoCon...

Page 35: ...le using either as alias or to a reference to file VBS In VBScript use the DoJavaScript method to execute a single JavaScript command objApp DoJavaScript alert alert text To open a JavaScript file use the DoJavaScriptFile method The following sample opens a file on the D drive Dim appRef As Photoshop Application Set appRef CreateObject Photoshop Application appRef DoJavaScriptFile D Scripts Mosaic...

Page 36: ...and VBScript scripting environments provide tools for monitoring the progress of your script while it is running which makes it easier for you to track down any problems your script might be encountering or causing AppleScript Debugging Apple s Script Editor application provides a syntax checking tool that you can use before you run your script Additionally Script Editor calls out problems in the ...

Page 37: ... box that displays the message My Message is MsgBox My Message Check your VBScript documentation for more information Windows Scripting Host also provides debugging information JavaScript Debugging JavaScript debugging is described in detail in the Adobe Photoshop CS2 JavaScript Scripting Reference on the Photoshop installation CD Please refer to that document for further information Error Handlin...

Page 38: ...ocument docName Alert errorMessage End Sub JS try for i 0 i app documents length i var myName app documents i name alert myName catch someError alert JavaScript error occurred Message someError description Bibliography AS For further information and instruction in using the AppleScript scripting language see these documents and resources AppleScript for the Internet Visual QuickStart Guide 1st ed ...

Page 39: ...osoft Press 1998 ISBN 1 572 31809 0 VBS VBSA in a Nutshell 1st ed Paul Lomax O Reilly 1998 ISBN 1 56592 358 8 Microsoft Developers Network MSDN scripting website msdn microsoft com scripting JS For further information and instruction in using the JavaScript scripting language see these documents and resources JavaScript The Definitive Guide David Flanagan O Reily Media Inc 2002 ISBN 0 596 00048 0 ...

Page 40: ... view the reference data for AppleScript and VBScript within your script editor environment Note JavaScript is a cross platform language and therefore does not require a specific script editor Viewing Photoshop CS2 s AppleScript Dictionary You use Apple s Script Editor application to view the dictionary Note The default location for the Script Editor is Applications AppleScript Script Editor To vi...

Page 41: ...o target Photoshop CS2 in AppleScript you must enclosing your script in the following statements tell application Adobe Photoshop CS2 end tell Note Because you include all commands in the tell block there is no need to reference the Application object throughout the script VBS In VBScript you can do any of the following to target the application Dim appRef Set appRef CreateObject Photoshop Applica...

Page 42: ...contains the object The following sample creates an art layer in the document contained in the variable named docRef make new art layer in docRef Note When you create object in AppleScript you actually add the object to an element the same way you add a VBScript or JavaScript object to a collection However in AppleScript the element name is implied in the make or set statement For example the stat...

Page 43: ...ame The add method is not valid with objects other than collection objects Similar to VBScript the JavaScript statement to create a document is documents add and not document add Note You can include an Application object reference if you wish The following statement is equivalent to the previous sample app documents add To add an ArtLayer object you must reference the Document object that will co...

Page 44: ... Document on page 40 Setting the Active Layer on page 41 Setting the Active Channels on page 41 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 t...

Page 45: ...tiveLayer docRef Layers Layer 1 Look up the ActiveLayer property in the Properties table of the Document object in the Interface chapter of the Adobe Photoshop CS2 Visual Basic Scripting Reference JS docRef activeLayer docRef layers Layer 1 Look up the activeLayer property in the Properties table of the Document object in the Interface chapter of the Adobe Photoshop CS2 Scripting Guide Setting the...

Page 46: ...Channels Opening a Document You use the open Open open command method of the Application object to open an existing document You must specify the document name that is the path to the file that contains the document with the command method Specifying File Formats to Open Because Photoshop CS2 supports many different file formats the open Open open command lets you specify the format of the documen...

Page 47: ...ence look up the PhotoCDOpenOptions or EPSOpenOptions objects The following examples demonstrate how to open a generic multi page multi image PDF document with the following specifications The document will open in a window that is 100 pixels high and 200 pixels wide The document will open in RGB mode with a resolution of 72 pixels inch Antialiasing will be used to minimize the jagged appearance o...

Page 48: ...ile C PDFFiles MyFile pdf Create a PDF option object var pdfOpenOptions new PDFOpenOptions pdfOpenOptions antiAlias true pdfOpenOptions height 100 pdfOpenOptions width 200 pdfOpenOptions mode OpenDocumentMode RGB pdfOpenOptions resolution 72 pdfOpenOptions page 3 pdfOpenOptions constrainProportions false open the file app open fileRef pdfOpenOptions restore unit settings app preferences rulerUnits...

Page 49: ...mbed color profile false format options standard matte background color matte save current document in file myFile as JPEG with options myOptions appending no extension without copying end tell VBS Dim appRef Set jpgSaveOptions CreateObject Photoshop JPEGSaveOptions jpgSaveOptions EmbedColorProfile True jpgSaveOptions FormatOptions 1 for psStandardBaseline jpgSaveOptions Matte 1 for psNoMatte jpgS...

Page 50: ...es object is a property of the Application object When you use the Preferences object in a VBScript script you must indicate its containment in the Application object appRef Preferences RulerUnits 2 for PsUnits 2 psInches appRef Preferences TypeUnits 1 for PsTypeUnits 1 psPixels In the Adobe Photoshop CS2 Visual Basic Scripting Reference look up the Preferences object to view all of the settings p...

Page 51: ...Photoshop CS2 JavaScript Scripting Reference look up the Application object property displayDialogs and then look up the constant DialogModes in the Constants chapter Working with the Photoshop CS2 Object Model This section contains information about using the objects in the Photoshop CS2 Object Model For information on object models see Object Model Concepts on page 7 and Photoshop CS2 s Object M...

Page 52: ...age 41 Save the current document See Saving a Document on page 44 Copy and paste within the active document or between different documents See Understanding Clipboard Interaction on page 66 Manipulating a Document Object The following examples demonstrate how to do the following Change the size of the image to 4 inches wide and 4 inches high Change the size of the document window or canvas to 5 in...

Page 53: ...erences rulerUnits Units PIXELS docRef crop new Array 10 20 40 50 45 20 20 72 docRef flipCanvas Direction HORIZONTAL Working with Layer Objects The Photoshop CS2 object model contains two types of layer objects ArtLayer objects which can contain image contents and are basically equivalent to Layers in the Photoshop CS2 application Note An ArtLayer object can also contain text if you use the kind p...

Page 54: ...t ArtLayers Add layerObj Name MyBlendLayer layerObj BlendMode 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 100 colorObj RGB Blue 0 Now apply fill to the current selection appRef ActiveDocume...

Page 55: ...ayer newLayerSetRef move layerRef ElementPlacement PLACEAFTER Referencing ArtLayer Objects When you create a layer in the Photoshop CS2 application rather than a script the layer is added to the Layers palette and given a number These numbers act as layer names and do not correspond to the index numbers of ArtLayer objects you create in a script Your VBScript script or JavaScript will always consi...

Page 56: ...Layer 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 current document to end of layerSetRef VBS In VBScript you must duplicate and place the layer Set layerSetRef docRef LayerSets Add Set layerRef docRe...

Page 57: ...le from the Photoshop CS2 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 method with the style s name as an argument enclosed in straight double quotes Note The layer style names are case sensitive Please refer to Photoshop CS2 Help for a list of styles and for more information ab...

Page 58: ... ArtLayer object and then use the kind property to convert it to a text 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 CS2 s Object Model on page 8 for information on the relationship between ArtLa...

Page 59: ...ext item 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 methods in the scripting references do the following In the Adobe Photoshop CS2 AppleScript Scripting Reference look up the Class text object properties and methods In the Adobe Photoshop CS2 Visual Basic Scripting...

Page 60: ... canvas is 1000 x 1000 pixels then the coordinate for the lower right corner is x axis 1000 and y axis 1000 You specify coordinate points that describe the shape you want to select as an array which then becomes the argument or parameter value for the select Select select command method The following examples assume that the ruler units have been set to pixels and create a selection by 1 Creating ...

Page 61: ...rt command method of the Selection object to a selection so you can work on the rest of the document layer or channel while protecting the selection ASinvert selection of current document VBSselRef Invert JSselRef invert Expanding Contracting and Feathering Selections You can change the size of a selected area using the expand contract and feather commands The values are passed in the ruler units ...

Page 62: ...cy 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 state...

Page 63: ...ocument combination type extended VBS selRef Load docRef Channels My Channel 2 2 indicates that the value of the constant psExtendSelection is 2 psExtendSelection JS selRef load docRef channels My Channel SelectionType EXTEND See section Understanding Clipboard Interaction on page 66 for examples on how to copy cut and paste selections Working with Channel Objects The Channel object gives you acce...

Page 64: ...InfoRef to copyrighted work set owner url of docInfoRef to http www adobe com VBS Set docInfoRef docRef Info docInfoRef Copyrighted 1 for psCopyrightedWork docInfoRef OwnerUrl http www adobe com JS docInfoRef docRef info docInfoRef copyrighted CopyrightedType COPYRIGHTEDWORK docInfoRef ownerUrl http www adobe com For information about other types of information properties you can associate with a ...

Page 65: ...om the history collection Use the Purge command to remove latter states from the History States collection as shown below ASpurge history caches VBSappRef Purge 2 for psPurgeTarget 2 psHistoryCaches JSapp purge PurgeTarget HISTORYCACHES The example below saves the current state applies a filter and then reverts back to the saved history state AS set savedState to current history state of current d...

Page 66: ... class path point info kind corner point anchor 100 100 left direction 100 100 right direction 100 100 set pathPointInfo2 to class path point info kind corner point anchor 150 200 left direction 150 200 right direction 150 200 set subPathInfo1 to class sub path info entire sub path pathPointInfo1 pathPointInfo2 operation shape xor closed false set newPathItem to make new path item in docRef with p...

Page 67: ...he Photoshop CS2 user interface Each color model has its own set of properties For example the RGB color class contains three properties 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 th...

Page 68: ...nverting Colors The following examples convert an RGB color to its CMYK equivalent AS The following script which assumes an RGB color 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 CS2 AppleScript Scripting Refere...

Page 69: ...qual colors foreground color with background color then VBSIf appRef ForegroundColor IsEqual appRef BackgroundColor Then JSif 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 myWebSafeCo...

Page 70: ...ilter in the Methods table of the artLayer object in the Interface chapter Other Filters If the filter type that you want to use on your layer is not part of the scripting interface you can use the Action Manager from a JavaScript to run a filter If you are using AppleScript VBScript or VBScript you can run the JavaScript from your script Refer to the Adobe Photoshop CS2 JavaScript Scripting Refer...

Page 71: ...application Adobe Photoshop CS2 activate select all of current document set current layer of current document to layer Background of current document set newDocRef to make new document past newDocRef Note In AppleScript you must select the entire layer before performing the copy VBS make firstDocument the active document Set docRef appRef ActiveDocument appRef docRef ArtLayers Background Copy Set ...

Page 72: ...y A type ruler which is active when using the type tool You set measurement unit types for the type ruler using the type units TypeUnits typeUnits property Note These settings correspond to those found in the Photoshop CS2 preference dialog under Photoshop Preferences Units Rulers on Mac OS or Edit Preferences Units Rulers in Windows Unit Values All languages support plain numbers for unit values ...

Page 73: ...ollowing script converts a point value to an inch value set pointValue to points 72 set inchValue to pointValue as inches When this script is run the variable inchValue will contain inches 1 which is 72 points converted to inches This conversion ability is built in to the AppleScript language Using Unit Values in Calculations To use a unit value in a calculation it is necessary to first convert th...

Page 74: ...pt methods look up the method in the Methods table of the object in the Interface chapter in the Adobe Photoshop CS2 JavaScript Scripting Reference Class Object AppleScript Properties VBScript Properties JavaScript Properties Document height width Height Width height width EPS open options height width Height Width height width PDF open options height width Height Width height width lens flare ope...

Page 75: ... appRef Preferences PointSize 2 2 indicates psPointType 2 PsPostScriptPoints JS 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 with Document Preferences on page 72 for an example of how to do this Sample Workflow ...

Page 76: ...ds upon the script created in the previous lesson Working with Document Preferences The sample scripts in this section activate a Photoshop CS2 Application object and then save the default configuration settings into variables so that they can be restored later when the script completes These are the default configurations you most probably set up in the Preferences dialog when you initially insta...

Page 77: ...create variables for the default settings set theStartRulerUnits to ruler units of settings set theStartTypeUnits to type units of settings set theStartDisplayDialogs to display dialogs change the settings set ruler units of settings to inch units set type units of settings to pixel units set display dialogs to never create variables for default document settings set theDocWidthInInches to 4 set t...

Page 78: ...he script for the next section comment the statements that restore the beginning preferences by adding hyphens as follows set ruler units of settings to theStartRulerUnits set type units of settings to theStartTypeUnits 5 Save the script as HelloWorldDoc VBS To work with document preferences 1 Create the following script See Creating and Running a VBScript on page 23 for details Private Sub Comman...

Page 79: ...shop CS2 close the document without saving it 5 To prepare the script for the next section comment the statements that restore the beginning preferences by adding straight single quotes as follows app Preferences RulerUnits startRulerUnits app Preferences TypeUnits startTypeUnits 6 Name the script HelloWorldDoc and save it JS To work with document preferences 1 Create the following script Note See...

Page 80: ...ll add a layer to the HelloWorldDoc script then change the layer to a text object that displays the text Hello World in red Before you begin do the following Make sure Photoshop CS2 is closed Open the script file HelloWorldDoc in your script editor application AS To create and specify details in a text item 1 Type the following code into the HelloWorldDoc script immediately before the commented st...

Page 81: ...named textColor create a SolidColor object whose color is red assign the object to textColor Set textColor CreateObject Photoshop SolidColor textColor RGB Red 255 textColor RGB Green 0 textColor RGB Blue 0 create an art 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...

Page 82: ...ipt from the Scripts menu choose File Script HelloWorldDoc Be patient while Photoshop CS2 executes your commands one by one 3 After viewing the document in Photoshop CS2 close Photoshop CS2 without saving the document Note Look up the following classes in the Adobe JavaScript Scripting Reference Object Reference chapter to see if you understand how you used them in this script SolidColor ArtLayer ...

Page 83: ...InPixels 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 Columns are arranged horizontally 0 indicates the top row in the document Lower right corner theDocWidthInPixels 2 theDocHeig...

Page 84: ...r number of generators 1 minimum wavelength 1 maximum wavelength 100 minimum amplitude 5 maximum amplitude 10 horizontal scale 100 vertical scale 100 wave type sine undefined areas repeat edge pixels random seed 0 2 Choose Run to run the script 3 After viewing the document in Photoshop CS2 close the document without saving it 4 Save the script in the Script Editor Note Look up the following classe...

Page 85: ...ollowing classes in the Adobe VBScript Scripting Reference to see if you understand how you used them in this script ArtLayer class ApplyWave method Rasterize method Selection class Select method JS To select an area and apply a wave filter to it 1 Type the following code into the script file HelloWorldDoc just above the commented statements that restore original preferences create new variables t...

Page 86: ... other half of our document Additionally because this is the last exercise in this that deals with our Hello World document we will uncomment the statements that reset our original application preferences for rulers and units AS To apply a motionblur filter to HelloWorldDoc 1 Type the following code into the script file HelloWorldDoc just above the commented statements that restore original prefer...

Page 87: ...TypeUnits 3 Choose Run Run Sub Userform or press F5 to run the script Note Look up the ArtLayer class ApplyMotionBlur method in the Adobe VBScript Scripting Reference to see if you understand how you used it in this script JS To apply a motionblur filter to HelloWorldDoc 1 Type the following code into the script file HelloWorldDoc just above the commented statements that restore original preferenc...

Page 88: ...op CS2 Scripting Guide Scripting Photoshop CS2 84 Note Look up the ArtLayer class applyMotionBlur method in the Adobe JavaScript Scripting Reference Object Reference chapter to see if you understand how you used it in this script ...

Page 89: ... clipboard commands 66 methods 66 collections defined 9 numbering in 9 referring to objects in 10 color objects applying to text 76 classes 64 comparing 65 defined 63 getting and converting 64 hex values 64 setting 64 web safe 65 working with 63 commands conventions 1 defined 6 finding 36 properties 12 using 12 comments 20 comparison operators 25 conditional logic 2 conditional statements 26 30 co...

Page 90: ...on characters 21 list value type 15 long script lines formatting 21 loops 26 M methods arguments 13 conventions 1 defined 6 finding 36 using 12 Motion Blur filter applying 82 MsgBox command 33 N Notifier object defined 9 using 61 O Object classes 19 Object elements or collections 9 Object inheritance 19 object model concepts 7 working with 47 Object references 11 47 objects Also see individual obj...

Page 91: ...nts AppleScript 3 JavaScript Mac OS 3 JavaScript Windows 4 Mac OS 3 VBScript 3 Windows 3 T text applying color 76 creating 55 stroking 77 Text Item object creating 54 working with 54 text layers 54 text value type 15 texting 32 troubleshooting 32 type units defined 68 setting 71 U units AppleScript considerations 69 as properties 69 in arguments 70 in calculations 69 setting 71 special types 68 va...

Reviews: