background image

 

ADOBE SYSTEMS INCORPORATED 

 

Corporate Headquarters

 

345 Park Avenue

San Jose, CA 95110-2704

(408) 536-6000

http://partners.adobe.com

 

bb

c

 

October 2003

 

Photoshop CS 
Scripting Guide

Summary of Contents for 23101764 - Photoshop CS - PC

Page 1: ...ADOBE SYSTEMS INCORPORATED Corporate Headquarters 345 Park Avenue San Jose CA 95110 2704 408 536 6000 http partners adobe com bbc October 2003 Photoshop CS Scripting Guide ...

Page 2: ...t 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 Photoshop and PostScript are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and or other countries Apple Macintosh and Mac are trademarks of Apple Computer Inc registered in the United States and other ...

Page 3: ...What s Next 7 Chapter 2 Scripting basics 8 2 1 Documents as objects 8 2 2 Object model concepts 8 2 3 Object Model 10 2 4 Documenting scripts 17 2 5 Values 18 2 6 Variables 20 2 7 Operators 22 2 8 Commands and methods 22 2 9 Handlers subroutines and functions 25 2 10 Debugging and Error Handling 26 2 11 What s Next 30 Chapter 3 Scripting Photoshop 31 3 1 Photoshop scripting guidelines 31 3 2 Viewi...

Page 4: ...its 57 3 7 Executing JavaScripts from AS or VB 62 3 8 The Application object 64 3 9 Document object 68 3 10 Layer objects 72 3 11 Text item object 77 3 12 Selections 81 3 13 Working with Filters 88 3 14 Channel object 89 3 15 Color objects 91 3 16 History object 94 3 17 Clipboard interaction 96 ...

Page 5: ...ed techniques for scripting the Photoshop application Note Please review the README file shipped with Photoshop CS for late breaking news sample scripts and information about oustanding issues 1 1 1 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 Visual Basic and JavaScript P...

Page 6: ...ists of values specific to each scripting language 1 2 What is scripting 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 complex and affect many objects in a Photoshop document The actions can call Photoshop alone or invoke ...

Page 7: ...o take care of it 1 4 What about actions Photoshop actions are different from scripts A Photoshop action is a series of tasks you have recorded while using the application menu choices tool choices selection and other commands When you play an action Photoshop performs all of the recorded commands Actions and scripts are two ways of automating repetitive tasks but they work very differently You ca...

Page 8: ...nd productivity features not found in the Script Editor There are many third party script editors that can write and debug Apple Scripts For more details check http www apple com applescript We use the Script Editor from Apple in this manual For more information on the AppleScript scripting environment see Section 3 2 1 Viewing Photoshop s AppleScript dictionary 1 5 2 Windows Any Windows system th...

Page 9: ... Do you need to run the same script on both Macintosh and Windows computers 2 Do you need to control multiple applications from the same script As mentioned earlier JavaScript is a cross platform language that works on either platform The same script will perform identically on Windows and Macintosh computers However JavaScript is invoked from the Scripts menu within Photoshop and lacks the facili...

Page 10: ...ps you can create manage and view multiple versions of a layout in a single Photoshop or ImageReady file Web Photo Gallery One of the most popular features of Photoshop is the ability to create a web photo gallery out of a folder of files You can now perform the same function through scripting JavaScripts get their own Scripts menu JavaScripts now join AppleScript and Visual Basic scripts as first...

Page 11: ...ies and data such as camera settings and photo captions can be captured during the content creation process and embedded within the file Meaningful descriptions and titles searchable keywords and up to date author and copyright information can be captured in a format that is easily understood by you as well as by software applications hardware devices and file formats To access XMP metadata via sc...

Page 12: ...nd their properties as components of an object model Imagine that you live in a house that responds to your commands The house is an object and its properties might include the number of rooms the color of the exterior paint or the date of its construction Your house can also contain other objects within Each room for example is an object in the house while each window door or appliance is an obje...

Page 13: ...aScript are objects contained within other objects For example rooms are elements or collections of our house contained within the house object In Photoshop documents are elements of the application object and layers are elements of a document object To access an element or member of a collection you use an index For example to get the first document of the application you write AS document 1 VB a...

Page 14: ...n fewer bugs and are easier to maintain In the object model illustrated below the Photoshop Application object sits at the top of the containment hierarchy The Document object directly below the Photoshop application is the the active object you are working with and the gateway to the main components of the Photoshop object model Document Class The Document class is used to make modifications to t...

Page 15: ...rder to manipulate just the red pixels in the image or you could choose to manipulate all the channels at once These kinds of channels are related to the document mode and are called component channels In addition to the component channels Photoshop lets you to create additional channels You can create a spot color channel a masked area channel and a selected area channel Using the methods of a Ch...

Page 16: ... on page 72 History Class The History class is a palette object that keeps track of changes made to a document Each time you apply a change to an image the new state of that image is added to the palette These states are accessible from document object and can be used to reset the document to a previous state A history state can also be used to fill a selection For more information on history obje...

Page 17: ...object handles all colors The solid color classes available in Photoshop are illustrated below For more information on colors see Section 3 15 on page 91 Save Classes Open Classes Open Options Generic PDF Generic EPS Raw Photo CD Save Options Photoshop BMP GIF EPS JPEG PDF Pict File Pict Resource Pixar PNG TIFF Raw DSC1 DSC2 SGI RGB Targa RGB Color CMYK Color Grey Color HSB Color Lab Color No Colo...

Page 18: ...lved are the same Open the Photoshop application Create a new document object Add an art layer to the document Change the art layer to a text item Set the contents of the text item These steps mirror a specific path in the containment hierarchy as illustrated below The relationships exposed in the containment hierarchy are fully preserved in the scripting sequence Understanding the Object Model is...

Page 19: ...Sample Code This code contains Visual Basic commands that instruct Photoshop to configure the width and height of a new document in inches and place an art layer within the document The art layer is then changed to a text item whose contents are set to Hello World Initial unit settings are restored after the script is run Dim appRef As New Photoshop Application Dim originalRulerUnits As Photoshop ...

Page 20: ...es rulerUnits app preferences rulerUnits Units INCHES var docRef app documents add 4 2 72 Hello World var artLayerRef docRef artLayers add artLayerRef kind LayerKind TEXT var textItemRef artLayerRef textItem textItemRef contents Hello World docRef null artLayerRef null textItemRef null app preferences rulerUnits originalUnit Hello World Aside from minor differences in display format all three scri...

Page 21: ... Rem for remark or a single straight quote to the left of the comment Rem this is a comment and so is this JavaScript In JavaScript use the double forward slash to comment a single line or a notation for multi line comments This comments until the end of the line This comments this entire block of text About long script lines In some cases individual script lines are too long to print on a single ...

Page 22: ...rue integer Whole numbers no decimal points Integers can be positive or negative 14 real A number which may contain a decimal point 13 9972 string A series of text characters Strings appear inside straight quotation marks I am a string list An ordered list of values The values of a list may be any type 10 0 20 0 30 0 40 0 object reference A specific reference to an object current document record A...

Page 23: ...Array A list of values Arrays contain a single value type unless the type is defined as Variant Array 10 0 20 0 30 0 40 0 Object reference A specific reference to an object appRef ActiveDocument TABLE 2 3 JavaScript Values Value type What it is Example String A series of text characters Strings appear inside straight quotation marks Hello Number Any number not inside double quotes 3 7 Boolean Logi...

Page 24: ...ipt however it is considered good form to declare all of your variables before using them To declare variables in Visual Basic use the Dim keyword To declare variables in JavaScript use the var keyword 2 6 1 Assigning values to variables The remainder of this section shows how to assign values to variables AS set thisNumber to 10 set thisString to Hello World VB Option Explicit Dim thisNumber As L...

Page 25: ... reference use Set Set thisLayer appRef Photoshop ActiveDocument ArtLayers 1 If you are trying to assign a value to a variable in Visual Basic that is not an object reference do not use Set Use Visual Basic s assignment operator the equals sign thisNumber 12 JavaScript looks similar to Visual Basic To assign a reference to an object you would write var docRef app activeDocument and to assign a val...

Page 26: ...rejudice would return the string Pride and Prejudice JavaScript uses the operator to concatenate strings Pride and Prejudice would return the string Pride and Prejudice 2 8 Commands and methods Commands AppleScript or methods Visual Basic and JavaScript are what makes things happen in a script The type of the object you re working with determines how you manipulate it AS In AppleScript use the mak...

Page 27: ...les check the number of currently open documents If no documents are open the scripts display a messages in a dialog box AS tell application Adobe Photoshop CS set documentCount to count every document if documentCount 0 then display dialog No Photoshop documents are open end if end tell VB Private Sub Command1_Click Dim documentCount As long Dim appRef As New Photoshop Application documentCount a...

Page 28: ... loop is one that repeats a series of script operations a set number of times AS repeat with counter from 1 to 3 display dialog counter end repeat VB For counter 1 to 3 MsgBox counter Next JS for i 1 i 4 i alert i A more complicated type of control structure includes conditional logic so that it loops while or until some condition is true or false AS set flag to false repeat until flag true set fl...

Page 29: ...rm Are you sure var flag false do flag confirm Are you sure while flag false 2 9 Handlers subroutines and functions Subroutines or handlers in AppleScript and functions in JavaScript are scripting modules you can refer to from within your script These subroutines provide a way to re use parts of scripts Typically you send one or more values to a subroutine and it returns one or more values There s...

Page 30: ...nteger result DoConfirm Are you sure MsgBox result End Sub Function DoConfirm prompt As Boolean buttonPressed MsgBox prompt vbYesNo DoConfirm buttonPressed vbYes End Function JS var theResult DoConfirm Are you sure alert theResult function DoConfirm message var result confirm message return result 2 10 Debugging and Error Handling Scripting environments provide tools for monitoring the progress of...

Page 31: ...Event Log The Script Editor displays the Event Log window Check the Show Events and Show Events Results options at the top of the Event Log window and run your script As the script executes you ll see the commands sent to Photoshop and the Photoshop responses You can display the contents of one or more variables in the log window by using the log command log myVariable otherVariable In addition th...

Page 32: ... to continue normal execution of the script You can also observe the values of variables defined in your script using the Watch window a very valuable tool for debugging your scripts To view a variable in the Watch window select the variable and choose Debug Quick Watch Visual Basic displays the Quick Watch dialog box Click the Add button Visual Basic displays the Watch window If you have closed t...

Page 33: ...r message tell application Adobe Photoshop CS try set docRef to document My Document display dialog Found My Document on error display dialog Couldn t locate document My Document end try end tell VB Private Sub Command1_Click Store a reference to the document with the name My Document If the document does not exist display an error message Dim appRef As New Photoshop Application Dim docRef As Phot...

Page 34: ...e alert myName catch someError alert JavaScript error occurred Message someError description 2 11 What s Next The next chapter covers Photoshop specific objects and components and describes advanced techniques for scripting the Photoshop application The Hello World example is entended to include text filtering and document selection ...

Page 35: ...ript always create your document with a name and later get that document by name get the front most document set docRef to make new document with properties height pixels 144 width pixels 144 resolution 50 name My Document When working in VB or JavaScript store the document reference to a newly created document to reuse later When running AppleScripts and two documents are open with the same name ...

Page 36: ...ts cannot be displayed because of the large number of choices available The complete list of available open and save formats are listed below open anything the file s to be opened as Acrobat TouchUp Image Alias PIX BMP CompuServe GIF EPS EPS PICT preview EPS TIFF Preview Electric Image Filmstrip JPEG PCX PDF PICT file PICT resource PNG Photo CD Photoshop DCS 1 0 Photoshop DCS 2 0 Photoshop EPS Pho...

Page 37: ...OK button 3 Choose View Object Browser Visual Basic displays the Object Browser window 4 Choose Photoshop from the list of open libraries shown in the top left pull down menu 5 Click an object class such as Document see below to display more information 3 2 3 Viewing the JavaScript Environment Because JavaScript is platform independent there is no native script editor associated with it Photoshop ...

Page 38: ...nu The Scripts menu The Scripts menu displays under the Photoshop File menu When a Scripts item is selected a dialog is presented from which you can select a JavaScript for execution A collection of JavaScripts comes pre installed with Photoshop These scripts display alongside the Scripts menu as illustrated above You can use these scripts out of the box or create your own Use the Browse option to...

Page 39: ...the following script The lines preceded by are comments They re included to document the operation of the script and it s good style to include them in your own scripts As you look through the script you ll see how to create then address each object The AppleScript command tell indicates the object that will receive the next message we send Sample script to create a new text item and change its co...

Page 40: ...reference to the project as shown earlier If you are using a built in editor in a VBA application skip to step 4 2 Add a form to the project 3 Create a new button on the form Double click the button to open the Code window 4 Below we revisit the Hello World Visual Basic script from Chapter 2 with comments included We ll expand on this example in the Advanced Scripting section that follows ...

Page 41: ...s appRef Preferences RulerUnits psInches Create a new 4x4 inch document and assign it to a variable Dim docRef As Photoshop Document Dim artLayerRef As Photoshop ArtLayer Dim textItemRef As Photoshop TextItem Set docRef appRef Documents Add 4 4 Create a new art layer containing text Set artLayerRef docRef ArtLayers Add artLayerRef Kind psTextLayer Set the contents of the text layer Set textItemRef...

Page 42: ...tLayer in VBScript you say Dim aRef For VBScript simply omit the as and everything that comes after the as in this case Photoshop ArtLayer VBScript does not support the as New Photoshop Application form In Visual Basic you can retrieve the Application object as Dim appRef as New Photoshop Application In VBScript you write the following to retrieve the Application object Dim appRef Set appRef Creat...

Page 43: ...Ref docRef ArtLayers 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 To run this script create a text file and copy the script into it Save the file with a vbs extension Double click the file to execute 3 3 4 JavaScript 1 Locate and open the script e...

Page 44: ...ts 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 containing text var artLayerRef docRef artLayers add artLayerRef kind LayerKind TEXT Set the contents of the text layer var textItemRef artLayerRef textItem textItemRef contents Hello World Release references docRef null artLayerRef null textItemRef null Restore original rul...

Page 45: ... words In this section we describe sample code that takes you step by step through an extended script to successively produce the output illustrated below 3 4 1 Advanced JavaScript The following JavaScript code sample is broken down into four sections the first of which deals with configuring document preferences NOTE In JavaScript the Photoshop Application object is already created for you behind...

Page 46: ...at the script runs without user intervention Users will not in other words be required to press OK each time the script generates a new dialog for display Next variables are declared that store document dimensions in inches and document resolution in pixels Finally a document object is created if one does not already exist startRulerUnits app preferences rulerUnits startTypeUnits app preferences t...

Page 47: ... the text layer The content of the text layer is the expression Hello World Notice that the position property of the text layer is an array whose values were chosen to roughly center the text in the dialog A relatively large font size was chosen to increase the visibility of the text message The color property is the SolidColor object created earlier whose function is to display text in red docRef...

Page 48: ...her array values define vertical positioning With the width and height of the array thus defined select the left side of the document Ants marching up the page delimit the area selected You can now apply a wave filter to the selection A truncated sin curve carries the text along for a roller coaster like ride docWidthInPixels docWidthInInches resolution docHeightInPixels docHeightInInches resoluti...

Page 49: ...ngle and radius of the blur Then remove the selection so that the marching ants disappear from the dialog To finish up set application preferences back to their original values selRegion Array Array docWidthInPixels 2 0 Array docWidthInPixels 0 Array docWidthInPixels docHeightInPixels Array docWidthInPixels 2 docHeightInPixels Array docWidthInPixels 2 0 docRef selection select selRegion newTextLay...

Page 50: ...ntervention Users will not in other words be required to press OK each time the script generates a new dialog for display Next variables are declared that store document dimensions in inches and document resolution in pixels A display resolution is declared and the text Hello World is assigned to a string variable Finally a document object is created if one does not already exist Dim startRulerUni...

Page 51: ...e blank document displayed below Displaying Colored Text Having generated a default document you can now display colored text To do so first set a local reference to the current document Then create a SolidColor object and assign RGB color values to it You are now ready to create an art layer of type psTextLayer NOTE For a complete listing of all Visual Basic properties methods and constants such ...

Page 52: ...Str newTextLayer TextItem Position Array 0 75 1 newTextLayer TextItem Size 36 newTextLayer TextItem Color textColor This code snippet outputs Hello World in red Applying a Wave Filter Now that text displays on your document you re ready to apply some special effects First re define the width and height of the document in pixels Additionally convert the text layer to pixels we do this because text ...

Page 53: ...0 0 newTextLayer ApplyWave 1 1 100 5 10 100 100 _ Photoshop PsWaveType psSine _ Photoshop PsUndefinedAreas psWrapAround 0 This code snippet manipulates and bends the text on the left side of the document Applying a MotionBlur Filter Similar code can be used to blur the text in a document Again create an array of points to designate an area of the document This time the width is defined as the dist...

Page 54: ...vanced AppleScript The following AppleScript code sample is broken down into four sections the first of which deals with configuring document preferences Document Preferences In this code segment a Photoshop Application object is activated Default configuration settings for the application are saved into variables so that they can be restored later when the script completes These are the default c...

Page 55: ...rtRulerUnits to ruler units of settings set theStartTypeUnits to type units of settings set theStartDisplayDialogs to display dialogs set ruler units of settings to inch units set type units of settings to pixel units set display dialogs to never set theDocWidthInInches to 4 set theDocHeightInInches to 2 set theDocResolution to 72 set theDocString to Hello World if count of documents is 0 then mak...

Page 56: ...xt layer The contents of the text layer is the expression Hello World Notice that the position property of the text layer is an array whose values were chosen to roughly center the text in the dialog A relatively large font size was chosen to increase the visibility of the text message The color property is theTextColor created earlier whose function is to display text in red set theDocRef to the ...

Page 57: ...defined select the left side of the document Ants marching up the page delimit the area selected You can now apply a wave filter to the selection A truncated sin curve carries the text along for a roller coaster like ride set theDocWidthInPixels to theDocWidthInInches theDocResolution set theDocHeightInPixels to theDocHeightInInches theDocResolution rasterize theTextLayer affecting text contents s...

Page 58: ...ith parameters that define the angle and radius of the blur Then remove the selection so that the marching ants disappear from the dialog To finish up set application preferences back to their original values set theSelRegion to theDocWidthInPixels 2 0 theDocWidthInPixels 0 theDocWidthInPixels theDocHeightInPixels theDocWidthInPixels 2 theDocHeightInPixels theDocWidthInPixels 2 0 select theDocRef ...

Page 59: ...r example if you have a single document named My Document open you could target the document s first layer named Cloud Layer with either line layer 1 of document 1 or layer cloud layer of document My Document NOTE When scripting Phothshop a document s index is not always the same as its stacking order in the user interface It is possible for document 1 to not be the front most document For this re...

Page 60: ...f art layer L1 of current document to New Layer 1 7 end tell 3 5 2 Visual Basic and JavaScript Object references in Visual Basic and JavaScript are fixed and remain valid until disposed or until the host object goes away The following example shows how to create 2 layers and then rename the first one in Visual Basic Dim appRef As Photoshop Application Dim docRef As Photoshop Document Dim layer1Ref...

Page 61: ...ler is used for most operations on a document where height width or position are specified The type ruler is used when operating on text items such as when setting leading or indent values By changing the settings for each ruler you can work with documents in the measurement system that make the most sense for the project at hand 3 6 1 Unit values Photoshop uses unit values for certain properties ...

Page 62: ...nt ruler type Getting the height of the document created above set docHeight to height of current document would return a value of 5 0 which represents 5 inches based on the current ruler settings In AppleScript you can optionally ask for a property value as a particular type set docHeight to height of current document as points This would return a value of 360 5 inches x 72 points per inch IMPORT...

Page 63: ... calculation 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 someValue Special unit value types The unit values used by Photoshop are length units representing values of linear measurement Support is also included for pixel and percent unit values These two unit value types...

Page 64: ...idth height width EPS open options height width Height Width height width PDF open options height width Height Width height width lens flare open options height width Height Width height width offset filter horizontal offset vertical offset HorizontalOffset VerticalOffset horizontalOffset verticalOffset Text Item baseline shift first line indent height hyphenation zone leading left indent position...

Page 65: ... of settings to pixel units set point size of settings to postscript size TABLE 3 3 Command Parameters AppleScript Visual Basic JavaScript crop bounds height width Document Crop Bounds Height Width document crop bounds height width resize canvas height width Document ResizeCanvas Height Width document resizeCanvas height width resize image height width Document ResizeImage Height Width document re...

Page 66: ...ORTANT Remember to reset the unit settings back to the original values at the end of a script 3 7 Executing JavaScripts from AS or VB You may want to take advantage of the platform independence of JavaScript by running scripts from AppleScript or Visual Basic For AppleScript use do javascript For Visual Basic use either the Application s DoJavaScript or DoJavaScriptFile method DoJavaScript takes a...

Page 67: ...ument When running JavaScript from AppleScript or Visual Basic you can also control the debugging state To do this use the show debugger ExecutionMode argument The values of this argument include never NeverShowDebugger This option will disable debugging from the JavaScript Any error that occurs in the JavaScript will result in a JavaScript exception being thrown Note that you can catch JavaScript...

Page 68: ...y enclosing your Photoshop commands in the following statement AppleScript will understand you are targeting Photoshop tell application Adobe Photoshop CS end tell In Visual Basic you create and use a reference to the Application Typically you would write Set appRef CreateObject Photoshop Application In JavaScript there is no need for an application object and therefore all properties and methods ...

Page 69: ...logs properly from a script If a dialog is shown your script stops until a user dismisses the dialog This is normally fine in an interactive script that expects a user to be sitting at the machine But if you have a script that runs in an unsupervised batch mode you do not want dialogs to be displayed and stop your script Using the display dialogs DisplayDialogs displayDialogs property on the appli...

Page 70: ...contains values needed in your script Specifying file formats to open Because Photoshop supports many different file formats the Open command lets you specify the format of the document you are opening If you do not specify the format Photoshop will infer the type of file for you Here s how to open a document using its default type AS set theFile to alias MyFile psd open theFile VB fileName C MyFi...

Page 71: ...nalRulerUnits As Photoshop PsUnits originalRulerUnits appRef Preferences RulerUnits appRef Preferences RulerUnits psPixels Create a PDF option object Dim pdfOpenOptionsRef As Photoshop PDFOpenOptions Set pdfOpenOptionsRef CreateObject Photoshop PDFOpenOptions pdfOpenOptionsRef AntiAlias True pdfOpenOptionsRef Height 100 pdfOpenOptionsRef Width 200 pdfOpenOptionsRef mode psOpenRGB pdfOpenOptionsRef...

Page 72: ...can open the open document types may be different from the save document types 3 9 Document object After you target the Photoshop application the next object you will likely target is the Document object The Document object can represent any open document in Photoshop For example you could use the Document object to get the active layer save the current document then copy and paste within the acti...

Page 73: ...he save dialogs without completing the operation you could miss a dialog containing values needed in your script There are many objects that allow you to specify how you want to save your document For example to save a file as a JPEG file you would use the JPEG save options JPEGSaveOptions JPEGSaveOptions class as shown below AS tell application Adobe Photoshop CS make new document set myOptions t...

Page 74: ...ated with additional information such as the author via the File File Info menu The information found in this menu item is handled by the info DocumentInfo object To change document information reference the info object and set its properties as shown below AS set docInfoRef to info of current document set copyrighted of docInfoRef to copyrighted work set owner url of docInfoRef to http www adobe ...

Page 75: ...S resize image current document width 4 height 4 VB docRef ResizeImage 4 4 JS docRef resizeImage 4 4 Resizing the canvas is done similarly AS resize canvas current document width 4 height 4 VB docRef ResizeCanvas 4 4 JS docRef resizeCanvas 4 4 To trim the excess space from a document use the trim Trim trim command The example below will trim the top and bottom of the document AS trim current docum...

Page 76: ...ayers art layer and layer set Both types of layers have common properties such as visible The common attributes are placed in a general layer class that both art layer and layer set inherit from When you create a layer you must specify whether you are creating an art layer or a layer set The following examples show how to create an art layer filled with red at the beginning of the current document...

Page 77: ...d with the fill command Dim colorObj As Photoshop SolidColor 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 ActiveDocument Selection Fill colorObj JS Create a new art layer at the beginning of the current document var layerRef app activeDocument artLayers add layerRef name MyBlendLayer la...

Page 78: ... beginning of the document Dim newLayerSetRef As Photoshop LayerSet Set newLayerSetRef appRef ActiveDocument LayerSets Add Move the new layer to after the first layer newLayerSetRef Move layerRef psPlaceAfter JS 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...

Page 79: ...layers can be moved into layer sets The following examples show how to create a layer set duplicate an existing layer and move the duplicate layer into the layer set AS set current document to document My Document set layerSetRef 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 layerSetRe...

Page 80: ...ayerSetRef 3 10 3 Linking layers Scripting also supports linking and unlinking layers You may want to link layers together so that moving or transforming them can be done with one statement To link layers together do the following AS make new art layer in current document with properties name L1 make new art layer in current document with properties name L2 link art layer L1 of current document wi...

Page 81: ...ayers L1 applyStyle Puzzle Image 3 10 5 Rotating layers Use the rotate Rotate rotate command on the layer to rotate the entire layer Positive integers rotate the layer clockwise Negative integers rotate it counterclockwise AS rotate current layer of current document angle 45 0 VB docRef ActiveLayer Rotate 45 0 JS docRef activeLayer rotate 45 0 3 11 Text item object In Photoshop the Text object is ...

Page 82: ...he layer s kind to text layer psTextLayer LayerKind TEXT AS if kind of layerRef is text layer then VB If layerRef Kind psTextLayer Then JS if newLayerRef kind LayerKind TEXT The art layer class has a text object TextItem textItem property which is only valid when the art layer s kind is text layer You can use this property to make modifications to your text layer such as setting its contents chang...

Page 83: ...he contents of the text item To set the contents of a text item in AppleScript you would write set contents of text object of art layer Layer 1 of current document to Hello If you use a text item object reference to set the contents you will need to write set contents of contents of textItemRef to Hello The second contents of is needed because contents is a keyword which tells AppleScript to opera...

Page 84: ... 20 magenta 50 yellow 30 black 0 VB Set newColor CreateObject Photoshop SolidColor newColor CMYK Cyan 20 newColor CMYK Magenta 100 newColor CMYK Yellow 30 newColor CMYK Black 0 textLayerRef TextItem Color newColor JS var newColor new SolidColor newColor cmyk cyan 20 newColor cmyk magenta 100 newColor cmyk yellow 30 newColor cmyk black 0 textLayerRef color newColor 3 11 3 Setting fonts To set the f...

Page 85: ...TextItem Font ArialMT JS textLayer textItem font ArialMT 3 11 4 Warping text Warping is another common effect that can be applied to text To warp a text item object set the object s warp style WarpStyle warpStyle property The style to set it to is an enumeration AS set warp style of textItemRef to flag VB textLayerRef TextItem WarpStyle psFlag JS textLayerRef textItem warpStyle WarpStyle FLAG 3 12...

Page 86: ...selection use the select method with a type of replaced psReplaceSelection SelectionType REPLACED The other selection types are diminished extended and intersected The diminished type shrinks the current selection the extended selection type expands the current selection and the intersected type finds the intersection of the current selection and the new selection and replace the current selection...

Page 87: ...f ActiveDocument docRef Selection Select Array Array 50 60 Array 150 60 _ Array 150 120 Array 50 120 Type psReplaceSelection restore unit setting appRef Preferences RulerUnits originalRulerUnits JS remember unit settings and set to values expected by this script var originalRulerUnits app preferences rulerUnits app preferences rulerUnits Units PIXELS get selection and replace it app activeDocument...

Page 88: ...or background layers 3 12 3 Inverting selections When you invert a selection you are masking the selection so you can work on the rest of the document layer or channel while protecting the selection Here s how to invert the current selection AS invert selection of current document VB selRef Invert JS selRef invert 3 12 4 Expand contract and feather selections These three commands are used to chang...

Page 89: ...its originalRulerUnits appRef Preferences RulerUnits appRef Preferences RulerUnits psPixels Dim selRef As Photoshop Selection Set selRef appRef ActiveDocument Selection selRef Expand 5 selRef Contract 5 selRef Feather 5 Rem restore unit setting appRef Preferences RulerUnits originalRulerUnits JS remember unit settings and set to pixels var originalRulerUnits app preferences rulerUnits app preferen...

Page 90: ...illColor RGB Red 255 fillColor RGB Green 0 fillColor RGB Blue 0 selRef Fill fillColor mode psVividLightBlend _ Opacity 25 PreserveTransparency 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 10th item in the history state you w...

Page 91: ...nt document angle 45 VB docRef Selection RotateBoundary 45 JS app activeDocument selection rotateBoundary 45 3 12 7 Loading and storing selections Photoshop exposes the functionality to store and load selections Selections get stored into channels and loaded from channels The following examples store the current selection into a channel named My Channel and extend the selection with any selection ...

Page 92: ... applyXXX methods for Visual Basic and JavaScript The following examples apply the Gaussian blur filter to the active layer AS filter current layer of current document using Gaussian blur with options radius 5 VB docRef ActiveLayer ApplyGaussianBlur 5 JS docRef activeLayer applyGaussianBlur 5 3 13 1 Selecting channel s to filter When applying filters keep in mind they affect the selected channels ...

Page 93: ... 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 Visual Basic or VBScript you can still run a JavaScript from your script 3 14 Channel object The Channel object Channel channel gives you access to much of the available functionality on Photoshop c...

Page 94: ...colors or convert document mode to duo tone 3 14 2 Setting the active channel Because more than one channel can be active at a time when setting a channel you must provide a channel array The sample below demonstrates how to set the active channels to the first and third channel AS set current channels of current document to channel 1 of current document channel 3 of current document VB Dim theCha...

Page 95: ...e the RGB color class contains three properties red blue and green 3 15 1 Setting a Color Here s how to set the foreground color to a CMYK color in AppleScript set foreground color to class CMYK color cyan 20 0 magenta 90 0 yellow 50 0 black 50 0 Because you can use any color model you could also write the following to set the foreground to an RGB color set foreground color to class RGB color red ...

Page 96: ...ect Photoshop SolidColor solidColor CMYK Cyan 20 solidColor CMYK Magenta 90 solidColor CMYK Yellow 50 solidColor CMYK Black 50 JS var solidColor new SolidColor solidColor cmyk cyan 20 solidColor cmyk magenta 90 solidColor cmyk yellow 50 solidColor cmyk black 50 Hex values An RGB color can also be represented as a hex value The hexadecimal value is used to represent the three colors of the RGB mode...

Page 97: ...lor model ColorModel RGB Then alert It s an RGB color End If You can also ask the SolidColor object to convert its color to any of the supported models For example writing someColor cmyk will return a CMYKColor object representing the CMYK version of the color in someColor regardless of the color model of someColor The examples below show how to convert the foreground color to a Lab color AS Conve...

Page 98: ...asic and JavaScript The web safe color returned is an RGB color AS set myWebSafeColor to web safe color for foreground color VB Dim myWebSafeColor As Photoshop RGBColor Set myWebSafeColor appRef ForegroundColor NearestWebColor JS var webSafeColor new RGBColor webSafeColor app foregroundColor nearestWebColor 3 16 History object Photoshop keeps a history of the actions that affect the appearance of ...

Page 99: ...istory state of current document to savedState VB Set savedState docRef ActiveHistoryState docRef ApplyMotionBlur 20 20 docRef ActiveHistoryState savedState JS savedState docRef activeHistoryState docRef applyMotionBlur 20 20 docRef activeHistoryState savedState IMPORTANT Reverting back to a previous history state does not remove any latter states from the history collection Use the Purge command ...

Page 100: ... below shows how to copy the contents of art layer 2 to the clipboard AS activate select all of current document copy art layer 2 of current document NOTE In AppleScript you must select the entire layer before performing the copy VB docRef ArtLayers 2 Copy JS docRef artLayers 1 copy 3 17 2 Copy merged You can also perform a merged copy This will make a copy of all visible layers in the selected ar...

Page 101: ...n the current document You must make the paste command s target document the current document before using the command A new layer is created by the paste command and a reference to it is returned If there is no selection in the target document the contents of the clipboard are pasted into the geometric center of the document Here s how to paste into a document named Doc2 AS activate set current d...

Page 102: ...tents of the clipboard into the selection in a document The destination selection border is then converted into a layer mask You must make the paste command s target document the current document before using the command AS activate set newLayerRef to paste with clipping to selection VB Set newLayerRef docRef Paste True JS newLayerRef docRef paste true ...

Page 103: ...color 93 Hex values 92 Setting a Color 91 web safe colors 94 COM 5 Command and methods JavaScript 22 Commands and methods 22 AppleScript 22 Visual Basic 22 Comments in scripts 17 AppleScript 17 JavaScript 17 Visual Basic 17 Conditional statements 23 Control structures 24 Conventions in this guide 1 cross application capability 5 D Debugging AppleScript 27 Visual Basic 28 Defining selections 82 Dis...

Page 104: ...t value type 18 Long 19 N Number 18 19 Numeric value types 18 19 O Object classes 8 Object elements or collections 9 Object inheritance 9 Object Model 8 Channel class 11 Containment classes 12 Document class 10 Document Info class 12 History class 12 Layer classes 12 Selection class 11 Object reference 9 18 19 Object references 55 AppleScript 55 Visual Basic and JavaScript 56 open 13 Opening a doc...

Page 105: ...g text 81 Text values 18 19 U Units 57 AppleScript Length Unit Values 58 Changing ruler and type units 61 command parameters that take unit values 61 object properties that depend on unit values 60 special unit value types 59 V Value types array 19 boolean 18 19 double 19 integer 18 list 18 long 19 number 18 real 18 record 18 reference 18 19 string 18 19 text 18 19 Variables 20 Assigning values to...

Reviews: