Scripting Guide bc ® ® Adobe Photoshop cs2
© Copyright 2005 Adobe Systems Incorporated. All rights reserved. Adobe® Creative Suite 2 Photoshop® Scripting Guide for Windows® and Macintosh®. NOTICE: All information contained herein is the property of Adobe Systems Incorporated. No part of this publication (whether in hardcopy or electronic form) may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written consent of Adobe Systems Incorporated.
Contents 1 Introduction ................................................................................................................................. 1 About this manual.......................................................................................................................................................................... 1 What is scripting? ..................................................................................................................................................
Adobe Illustrator CS2 Visual Basic Scripting Reference Contents iv Sample Workflow Automation JavaScripts.........................................................................................................................71 Advanced Scripting .....................................................................................................................................................................72 Index ......................................................................................
1 Introduction About this manual This manual provides an introduction to scripting Adobe® Photoshop CS2® on Mac OS® and Windows®. Chapter one covers the basic conventions used in this manual and provides an overview of requirements for scripting Photoshop CS2. Chapter two covers the Photoshop CS2 object model as well as generic scripting terminology, concepts and techniques.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Introduction 2 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. What is scripting? A script is a series of commands that tells Photoshop CS2 to perform a set of specified actions, such as applying different filters to selections in an open document.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Introduction ● You can copy scripts from one computer to another. If you were using an Action and then switched computers, you’d have to recreate the Action. ● Scripts provide more versatility for automatically opening files. When opening a file in an action, you must hard code the file location. In a script, you can use variables for file paths. 3 Note: See Photoshop CS2 Help for more information on Photoshop CS2 Actions.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Introduction 4 JavaScript You can write JavaScripts on either the Mac OS or Windows platform using any text editor. You must save JavaScript files as text files with a .jsx extension. For more information, see ‘Creating and Running a JavaScript’ on page 24. Choosing a scripting language Your choice of scripting language is determined by two trade-offs: 1.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Introduction 5 Scripts that control multiple applications You can write scripts in either AppleScript or VBScript that control multiple applications. For example, on a Macintosh you can write an AppleScript that first manipulates a bitmap in Photoshop and then commands a web design application to incorporate it. You can write a script with similar capability on Windows using VBScript as the scripting language.
2 Scripting basics This chapter provides a brief introduction to the basic concepts and syntax of the scripting languages AppleScript, VBScript, and JavaScript. If you are new to scripting, you should read this entire chapter. If you are familiar with scripting or programming languages, you most likely will want to skip many sections in this chapter. Use the following list to locate information that is most relevant to you.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide ● Adobe Photoshop CS2 Visual Basic Scripting Reference ● Adobe Photoshop CS2 JavaScript Scripting Reference Scripting basics 7 Tip: Throughout this guide, explanations of how to create a script for a task are followed by instructions for looking up in the appropriate scripting reference the specific elements used in the script. Using these instructions will help you quickly understand how to script Photoshop CS2.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 8 To get the script to open that window, you’d simply add the command or method for opening it. Thus your scripting statement would look like this: In my house, in the living room, the window on the north wall: open it. Similarly, you could create a script in your house model to change the color of a door to blue.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 9 The following table provides information about each object. To create this object without using a script: Object Name Description Application The Photoshop CS2 application Start the Photoshop CS2 application. Document The working object, in which you create layers, channels, actions, and so on. In a script, you name, open, or save a document as you would a file in the application.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 10 Note: Your scripts place objects in elements or collections even when there is only one object of that type in the entire script, that is, only one object in the element or collection. When you add an object, the object is numbered automatically within its respective element or collection. You can identify the object in other script statements by using its element or collection name and assigned number.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 11 AS In AppleScript, you use the object type name followed by a space and then the index. The following statement refers to the current document. Notice that the element name is implied rather than used explicitly. document 1 Note: If the element name were used, this statement would be document 1 of documents. AppleScript abbreviates the syntax by inferring the element name from the object type name.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 12 VBS Object index reference: appRef.ActiveDocument.LayerSets(0).Layers(0) Object name reference: appRef.ActiveDocument.LayerSet("Silhouettes").Layer(“Profile”) You can also combine the two types of syntax: appRef.ActiveDocument.LayerSets(1).Layer(“Profile”) Tip: Notice that when you refer to an object by its assigned name you use the object classname, which is singular (LayerSet or Layer).
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 13 Some commands require additional data. In AppleScript, the make new command adds a new object. You can specify properties for the object by enclosing the properties in brackets and preceding the brackets with the phrase with properties. The following statement creates a new document that is four inches wide and two inches high.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 14 Why Use Variables? There are several reasons for using variables rather than entering values directly in the script. ● Variables make your script easier to update or change.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 15 Using the Variable in a Script After declaring and assigning values to your variables, you use the variables in your script to represent the value; you use only the variable name without the set or copy command. The following statement uses the display dialog command to create a dialog box with the text Hello World.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 16 To assign a value to a variable, you use the equals sign (=), as follows: thisNumber = 10 thisString = "Hello, World" Note: Remember to enclose string values in straight, double quotes (""). Another rule of thumb for proper scripting in VBScript is to declare all of your variables somewhere near the beginning of the script. That way you can easily see which variables are in use without having to search throughout the script for them.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics Value Type What It Is Example (Continued) 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." "" JS The var keyword declares (that is, creates) variables in JavaScript.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 18 script a year after you write it, such as x or c. You can also give your variable names a standard prefix so that they’ll stand out from the objects, commands, and keywords of your scripting system. For example, you could use the prefix “doc” at the beginning of any variables that contain Document objects, or “layer” to identify variables that contain Art Layer objects. ● Variable names must be a single word (no spaces).
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 19 Understanding and Finding Constants Constants are a type of value that defines a property. Using the example of the kind property of an Art Layer object, you can define only specific kinds that Photoshop CS2 allows. In JavaScript, you must use constants exactly as they are defined—with the exact spelling and capitalization. In VBScript, you use a constant’s enumerated value.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 20 myFiles[1] = “clouds.gif” myFiles[2] = “clouds.jpg” myFiles[3] = “clouds.pdf” Notice that each value is numbered. To use a value in a statement, you must include the number. The following statement opens the file clouds.gif : open(myFiles[1]) The following sample includes the same statements in VBScript: Dim myFiles (4) myFiles(0) = “clouds.bmp” myFiles(1) = “clouds.gif” myFiles(2) = “clouds.jpg” myFiles(3) = “clouds.pdf” appRef.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 21 Note: Generally, your scripts are easier to read if you format all comments as single-line comments because the comment status of the line is indicated at the beginning of the line. VBS In VBScript, enter a single straight quote ( ' ) to the left of the comment. ' this is a comment Dim thisString ' this is an end-of-line comment Note: VBScript does not support multi-line comments.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 22 ➤ Our Hello World scripts will do the following: 1. Open the Photoshop CS2 application. 2. Create a new Document object. When we create the document, we 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.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics Note: The lines preceded by “--” are comments. Entering the comments is optional. -- Sample script to create a new text item and -- change its contents. --target Photoshop CS2 tell application "Adobe Photoshop CS2" -- Create a new document and art layer. set docRef to make new document with properties ¬ {width:3 as inches, height:2 as inches} set artLayerRef to make new art layer in docRef -- Change the art layer to be a text layer.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 24 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 CS2. Creating and Running a JavaScript Follow these steps to create and run a JavaScript that displays the text Hello World! in a Photoshop CS2 document.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 25 3. Do either of the following: ● If Photoshop CS2 is already open, choose File > Scripts > Browse, and then navigate to the Presets > Scripts folder and choose your script. ● Start or restart Photoshop CS2, and then choose File > Scripts, and then select your script from the Scripts menu. What’s Next The remainder of this chapter provides information about general scripting tips and techniques.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 26 Using Conditional Statements Conditional statements give your scripts a way to evaluate something and then act according to the result. For example, you may want your script to detect the blend mode of a layer or the name or date of a history state. Most conditional statements contain the word if, or the words if and then.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 27 AS Set counter to 1 repeat with counter from 1 to 3 display dialog counter end repeat VBS In VBScript, this type of loop is called a For-Next loop. Dim counter As Integer For counter = 1 to 3 Alert counter Next JS In JavaScript, this type of loop is called a for loop. Note: In the following script, the variable that contains the counter is named i.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 28 3. When the user clicks OK (for “Please quit!”), the script displays a different dialog that asks if the user is sure they want to quit. 4. When the user clicks Cancel in the new dialog, they see the second dialog again. 5. When the user clicks OK, the loop ends and the dialogs quit appearing.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 29 { /*create a confirm dialog with the text Quit? and two response buttons change the value of flag to the selected response*/ flag = confirm("Quit?") } //change the value of flag back to false var flag = false do { flag = confirm("Are you sure?") } while (flag == false) Using Subroutines, Handlers and Functions Subroutines are scripting modules you can refer to from within your script. They allow you to re-use parts of scripts.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 30 on DoConfirm(prompt) set button to button returned of (display dialog prompt ¬ buttons {"Yes", "No"} default button 1) return button = "Yes" end DoConfirm VBS In VBScript, subroutines begin with the keyword Sub and do not return a value. If you would like your subroutine to return a value, you must make it a function. Functions begin with the keyword Function.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 31 } Executing JavaScripts from AS or VBS You can take advantage of JavaScript’s platform-independence by running scripts from AppleScript or VBScript. You can execute either a single JavaScript statement or a complete JavaScript file. AS To run a JavaScript from AppleScript, you use the do javascript command. The following sample executes a single JavaScript command, which displays an alert box with the text alert text.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 32 end tell VBS Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application") appRef.DoJavaScriptFile "C:\\Applications\Scripts\JSFile.jsx", _ Array(1, "test text", appRef.ActiveDocument) When running JavaScript from AppleScript or VBScript you can also control the debugging state. To do this, use the show debugger (ExecutionMode) argument.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 33 command. The following sample requests the display of the variables myVariable and otherVariable. log {myVariable, otherVariable} ➤ To view results in the Results window rather than the Event Log: 1. Choose Controls > Show Result. Note: Third-party editors offer additional debugging features.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics 34 VBS 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 Photoshop.Document Dim errorMessage As String Dim docName As String docName = "My Document" Set docRef = appRef.ActiveDocument On Error GoTo DisplayError Set docRef = appRef.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting basics VBS For further information and instruction in using VBScript and the VBSA scripting language, see these documents and resources: ● “Learn to Program with VBScript 6,” 1st ed., John Smiley, Active Path, 1998. ISBN 1-902-74500-0. ● “Microsoft VBScript 6.0 Professional,” 1st ed., Michael Halvorson, Microsoft Press, 1998. ISBN 1-572-31809-0. ● “VBS & VBSA in a Nutshell,” 1st ed., Paul Lomax, O’Reilly, 1998. ISBN 1-56592-358-8.
3 Scripting Photoshop CS2 This chapter demonstrates several techniques for creating scripts to use specifically with Photoshop CS2. More importantly, you will learn how to use the Photoshop CS2 scripting references to find the objects, classes, properties, commands/methods, and even some values (called constants or enumerations) you can use to create AppleScripts, VBScript scripts, and JavaScripts for Photoshop CS2.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 37 ➤ To view the VBS object library: 1. Start Word, and then choose Tools > Macro > Visual Basic Editor. 2. Choose Tools > References., and then select the Adobe Photoshop CS2 Type Library check box and click OK. 3. Choose View > Object Browser. 4. Choose Photoshop CS2 type library from the list of open libraries shown in the top-left pull-down menu. 5. Choose an object class to display more information abut the class.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 38 New icon on the appropriate palette. This section demonstrates how to accomplish these same tasks in a script. To create an object in a script, you name the type of object you want to create and then use the following command/method: ● AS: make ● VBS: Add ● JS: add() As you can see in the Photoshop CS2 Object Model, the Document object contains all other objects except the Application object.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 39 You must use the collection name, which is a plural form of the object name, as follows: appRef.Documents.Add() Note: In this sample statement, the Application object is referenced via a variable named appRef. See ‘Targeting and Referencing the Application Object’ on page 37 for more information. To add an ArtLayer object, you must reference both the Application and Document objects that will contain the art layer.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 ● In VBScript, you use the ActiveObject property of the parent object (such as ActiveDocument or ActiveLayer). ● In JavaScript, you use the activeObject property of the parent object (such as activeDocument or activeLayer). 40 Note: The parent object is the object that contains the specified object. For example, the application is the parent of the document; a document is the parent of a layer, selection, or channel.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 JS // Create 2 documents var docRef = app.documents.add( 4, 4) var otherDocRef = app.documents.add (4,6) //make docRef the active document app.activeDocument = docRef //here you would include command statements //that perform actions on the active document.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 42 docRef.ActiveChannels = 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.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 43 JS var fileRef = new File("//MyFile") var docRef = app.open (fileRef) Notice that in JavaScript, you must create a File object and then pass a reference to the object to the open() command. For the document types on the following list, you can set options to specify how the document will be opened, such as the height and width of the window in which the document is opened, which page to open to in a multi-page file, etc.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 44 'Create a PDF option object Dim pdfOpenOptionsRef Set pdfOpenOptionsRef = CreateObject("Photoshop.PDFOpenOptions") pdfOpenOptionsRef.AntiAlias = True pdfOpenOptionsRef.Height = 100 pdfOpenOptionsRef.Width = 200 pdfOpenOptionsRef.mode = psOpenRGB pdfOpenOptionsRef.Resolution = 72 pdfOpenOptionsRef.Page = 3 pdfOpenOptionsRef.ConstrainProportions = False ' open the file Dim docRef Set docRef = appRef.Open(C:\\PDFFiles\MyFile.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 Save Classes Photoshop Pixar Save Options BMP GIF EPS JPEG PDF PNG TIFF Raw DSC1 DSC2 File Pict Pict Resource SGI RGB Targa Note: It is important to note that the Open and Save formats are not identical. See ‘Opening a Document’ on page 42 for comparison.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 46 jpgSaveOptions.embedColorProfile = true jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE jpgSaveOptions.matte = MatteType.NONE jpgSaveOptions.quality = 1 app.activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE) Setting Application Preferences Your script can set application preferences such as color picker, file saving options, guide-grid-slice settings, and so on.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 47 Note: Using dialogs in your script is roughly equivalent to using stops in a Photoshop CS2 action. AS The following script prevents dialogs from being displayed: set display dialogs to never In the Adobe Photoshop CS2 AppleScript Scripting Reference, look up the Class application to find the values you can use for the display dialogs property.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide ● Scripting Photoshop CS2 48 JS: var fontstInstalled = app.fonts ● The amount of unused memory available to Adobe Photoshop CS2. ● The location of the Presets folder. Note: See ‘Creating and Running a JavaScript’ on page 24 for information on the Presets folder. Using the Document Object The Document object can represent any open document in Photoshop CS2. You can think of a Document object as a file; you can also think of it as a canvas.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 VBS 'this script sample assumes the ruler units have been set to inches docRef.ResizeImage 4,4 docRef.ResizeCanvas 4,4 docRef.Trim Type:=psTopLeftPixel, Top:=True, Left:=False, _ Bottom:=True, Right:=False 'the crop command uses unit values 'change the ruler units to pixels app.Preferences.RulerUnits = Photoshop.PsUnits.psPixels docRef.Crop Array(10,20,40,50), Angle:=45, Width:=20, _ Height:=20, Resolution:=72 docRef.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 50 Creating an ArtLayer Object The following examples demonstrate how to create an ArtLayer object filled with red at the beginning of the current document.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 51 The following examples show how to create a Layer Set object after the creating the first ArtLayer object in the current document: AS tell application "Adobe Photoshop CS2" make new layer set after layer 1 of current document end tell VBS Dim appRef Set appRef = CreateObject("Photoshop.Application") ' Get a reference to the first layer in the document Dim layerRef Set layerRef = appRef.ActiveDocument.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 Note: Unlike object references in JavaScript or VBScript, AppleScript object reference names do not remain constant. Refer to an AppleScript language guide or text book for information on referencing a file using either as alias or to a reference to file. VBS Layers("Layer 3").Select JS layers["Layer 3"].
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.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 54 Using the Text Item Object You can change an existing ArtLayer object to a text layer, that is, a Text Item object, if the layer is empty. Conversely you can change a Text Item object to an ArtLayer object. This “reverse” procedure rasterizes the text in the layer object. The Text Item object is a property of the ArtLayer object.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 55 JS if (newLayerRef.kind == LayerKind.TEXT) Adding and Manipulating Text in a Text Item Object The following examples add and right-justify text in a text layer. AS set contents of text object of art layer "my text" to "Hello, World!" set justification of text object of art layer "my text" of ¬ current document to right VBS Set textItemRef = artLayers("my text").TextItem textItemRef.Contents = "Hello, World!" docRef.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide ● Scripting Photoshop CS2 56 In the Adobe Photoshop CS2 Visual Basic Scripting Reference and the Adobe Photoshop CS2 JavaScript Scripting Reference, look up selection in the Properties table for the Document object. Also, look up the select in the Methods table for the Selection object. Creating and Defining a Selection To create a selection, you use the select/Select/select() command/method of the Selection object.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 57 Stroking the Selection Border The following examples use the stroke (Stroke/stroke()) command/method of the Selection object to stroke the boundaries around the current selection and set the stroke color and width. Note: The transparency parameter cannot be used for background layers.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 58 selRef.Contract 5 selRef.Feather 5 JS var selRef = app.activeDocument.selection selRef.expand( 5 ) selRef.contract( 5 ) selRef.feather( 5 ) Filling a Selection You can fill a selection either with a color or a history state.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 59 Loading and Storing Selections You can store Selection objects in, or load them from, Channel objects.The following examples use the store/Store/store() command/method of the Selection object to store the current selection in a channel named My Channel and extend the selection with any selection that is currently in that channel.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 60 Note: Component channels are related to the document mode. Refer to Photoshop CS2 Help for information on channels, channel types, and document modes. AS set kind of myChannel to selected area channel VBS channelRef.kind = 3 'for psSelectedAreaAlphaChannel 'from the constant value psChannelType JS channelRef.kind = ChannelType.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 61 In a script, you can access a Document object’s history states using the HistoryStates object, which is a property of the Document object. You can use a HistoryStates object to reset a document to a previous state or to fill a Selection object. The following examples revert the document contained in the variable docRef back to the form and properties it had when it was first saved.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 62 Note: This type of script corresponds to selecting Start Application in the Script Events Manager (File > Scripts > Script Events Manager) in the Photoshop CS2 application. Please refer to Photoshop CS2 Help for information on using the Script Events Manager.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 63 JS //line #1--it’s a straight line so the coordinates for anchor, left, and //right //for each point have the same coordinates var lineArray = new Array() lineArray[0] = new PathPointInfo lineArray[0].kind = PointKind.CORNERPOINT lineArray[0].anchor = Array(100, 100) lineArray[0].leftDirection = lineArray[0].anchor lineArray[0].rightDirection = lineArray[0].anchor lineArray[1] = new PathPointInfo lineArray[1].kind = PointKind.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 64 solidColorRef.cmyk.magenta = 90 solidColorRef.cmyk.yellow = 50 solidColorRef.cmyk.black = 50 foregroundColor = solidColorRef Solid Color Classes The solid color classes available in Photoshop CS2 are illustrated below. Solid Color Color Classes RGB CMYK Color Color Gray Color HSB Color Lab Color No Color Using Hex Values You can express RGB colors as hex (or hexadecimal) values.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 65 someColor.cmyk 'someColor.model = 2 indicates psColorModel --> 2 (psRGBModel) End If Look up the following in the Adobe Photoshop CS2 Visual Basic Scripting Reference: ● model and cmyk in the Properties table of the SolidColor object JS This example uses the foregroundColor property of the Application object to get the original color to be converted. var someColor = foregroundColor.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 66 The following examples apply the Gaussian blur filter to the active layer. AS Use the filter command and then both specify the layer and the name of the filter and any options.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 67 Using the Copy and Paste Commands/Methods The following examples copy the contents an the background layer to the clipboard, create a new document, and then paste the clipboard contents to the new document. The scripts assume that there is a document already open in Photoshop CS2 and that the document has a background layer.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 68 VBS In VBScript, you must use the ArtLayer or Selection object’s Copy method with the Merge parameter. To perform the merged copy, you must enter, or pass, the value true, as in the following example. docRef.Selection.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 69 speaking, length values but are included because they are used extensively by Photoshop CS2 for many operations and values. AppleScript Unit Considerations AppleScript provides an additional way of working with unit values. You can provide values with an explicit unit type where unit values are used. When a typed value is provided its type overrides the ruler’s current setting.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 70 ● Look up the class’s properties in the “Objects” chapter of the Adobe Photoshop CS2 AppleScript Scripting Reference. ● Look up the property in the object’s Properties table in the “Objects” chapter of the Adobe Photoshop CS2 Visual Basic Scripting Reference or the Adobe Photoshop CS2 JavaScript Scripting Reference.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide AppleScript Scripting Photoshop CS2 VBScript 71 JavaScript (Continued) resize image (height, width) Document.ResizeImage (Height, Width) document.resizeImage (height, width) contract (by) Selection.Contract (By) selection.contract (by) expand (by) Selection.Expand (By) selection.expand (by) feather (by) Selection.Feather (By) selection.feather (by) select border (width) Selection.SelectBorder (Width) selection.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 72 your application directory. See Creating and Running a JavaScript for information on the Presets/Scripts folder. Script Name Description Layer Comps to Files.jsx Saves layer comps as files. Layer Comps to PDF.jsx Saves layer comps as a PDF presentation. Layer Comps to WPG.jsx Saves layer comps as a Web photo gallery. Export Layers to Files.jsx Exports each document in the document to a separate file.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 73 Preference Set to What it does (Continued) units pixels Uses pixels as the unit of measurement for text (type) dialog modes never Suppresses the use of dialogs so that your script executes without the user being asked for input (such as clicking an OK button) at various stages of the process. Note: dialog modes is not an option in the Photoshop CS2 application.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 74 --check to see whether any documents are open --if none are found, create a document --use the default document settings as its properties if (count of documents) is 0 then make new document with properties ¬ {width:theDocWidthInInches, height:theDocHeightInInches,¬ resolution:theDocResolution, name:theDocString} end if --change the settings back to the original units stored in the variables set ruler units of settings to theSta
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 75 appRef.DisplayDialogs = 3 'for PsDialogModes --> 3 (psDisplayNoDialogs) docWidthInInches = 4 docHeightInInches = 2 resolution = 72 helloWorldStr = "Hello, World!" 'see if any documents are open 'if none, create one using document defaults If appRef.Documents.Count = 0 Then app.Documents.Add docWidthInInches, docHeightInInches, resolution, helloWorldStr End If 'restore beginning preferences appRef.Preferences.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 76 if (app.documents.length == 0) app.documents.add(docWidthInInches, docHeightInInches, resolution) //restore beginning preferences app.preferences.rulerunits = startRulerUnits app.preferences.typeunits = startTypeUnits app.displayDialogs = startDisplayDialogs 2. Name the script HelloWorldDoc.jsx and save it in the Scripts folder. 3. Open Photoshop CS2 and choose File > Scripts > HelloWorldDoc to run the script. 4.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 77 set stroke color of text object of theTextLayer to theTextColor 2. Run the complete script. Be patient while Photoshop CS2 executes your commands one by one. 3. After viewing the document in Photoshop CS2, close the document without saving it.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 78 JS ➤ To create and specify details in a text item: 1. Type the following code into the HelloWorldDoc script immediately before the commented statements that restore original preferences. //create a reference to the active document docRef = app.activeDocument //create a variable named textColor //create a SolidColor object whose color is red //assign the object to textColor textColor = new SolidColor textColor.rgb.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide ● Scripting Photoshop CS2 79 Apply a wave filter to the selection. Note: The wave is a truncated sine curve. Defining the Area of a Selection Object To define the area of a selection object, we will create an array of coordinates, or points specified in pixels within the document.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 80 set theDocWidthInPixels to theDocWidthInInches *¬ theDocResolution set theDocHeightInPixels to theDocHeightInInches *¬ theDocResolution --use the rasterize command of the art layer object rasterize theTextLayer affecting text contents --create a variable named theSelRegion --assign an array of coordinates as its value set theSelRegion to {{0, 0}, ¬ {theDocWidthInPixels / 2, 0}, ¬ {theDocWidthInPixels / 2, theDocHeightInPixels},
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 81 'use the Rasterize() method of the ArtLayer class to 'convert the text in the ArtLayer object (contained in the newTextLayer variable) 'to postscript text type newTextLayer.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.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 82 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 CS2 and select the script from the Scripts menu (choose File > Script > HelloWorldDoc). 3. After viewing the document in Photoshop CS2, close Photoshop CS2 without saving the document.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 83 Note: Look up the motion blur class in the Adobe AppleScript Scripting Reference 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 commented statements that restore original preferences. docRef.Selection.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Scripting Photoshop CS2 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: 84
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Index A actions, vs.
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide Visual Basic 34 F filters MotionBlur, applying 82 Wave, applying 78 working with 65 functions 29 H handlers 29 Hello World script 21–25 History State object defined 9 using 60 I indexes 10 indices 10 inheritance 19 J JavaScript conventions 1 executing from AppleScript 31 executing from VBScript 31 system requirements (Mac OS) 3 system requirements (Windows) 4 JavaScripts creating 24 debugging 33 running 24 storing 4 L languages, choosing 4 Layer objects
Photoshop CS2 Adobe Photoshop CS2 Scripting Guide defined 68 setting 71 S saving documents 44 Script Editor defined 3 location 22 using 22 scripting choosing a language 4 defined 2 legacy OLE automation 4 vs actions 2 scripts capabilities 2 controlling multiple applications 4 cross platform 4 statements 7 Scripts folder 4 Selection object creating 56 defined 9 feathering 57 filling 58 inverting 57 loading 59 resizing 57 storing 59 stroking 57 working with 55 Solid Color classes 64 statements, scripting 7 s