SCRIPTING GUIDE bc
© Copyright 2007 Adobe Systems Incorporated. All rights reserved. Adobe® Creative Suite® 3 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 ................................................................................................................................. 5 About this manual.......................................................................................................................................................................... 5 Conventions in this guide ...........................................................................................................................................
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Contents 4 Working with Channel Objects .........................................................................................................................................45 Using the Document Info Object .....................................................................................................................................46 Using History State Objects.....................................................................................
1 Introduction About this manual This manual provides an introduction to scripting Adobe® Photoshop® CS3 on Mac OS® and Windows®. Chapter one covers the basic conventions used in this manual. Chapter two covers a brief overview of scripting, how to execute scripts, and the Photoshop CS3 object model. Chapter three covers Photoshop CS3-specific objects and components and describes advanced techniques for scripting the Photoshop CS3 application.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Introduction In this case, display dialogs refers to the AppleScript property, DisplayDialogs refers to the VBScript property and displayDialogs refers to the JavaScript property. For larger blocks of code, scripting examples are listed on separate lines. AS layer 1 of layer set 1 of current document VBS appRef.ActiveDocument.LayerSets(1).Layers(1) JS app.activeDocument.layerSets[0].
2 Photoshop CS3 Scripting Basics This chapter provides an overview of scripting for Photoshop, describes scripting support for the scripting languages AppleScript, VBScript, and JavaScript, how to execute scripts, and covers the Photoshop CS3 object model. It provides a simple example of how to write your first Photoshop CS3 script. If you are familiar with scripting or programming languages, you most likely will want to skip much of this chapter.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics ● A single script can perform actions that involve multiple applications. For example, depending on the scripting language you are using, you could target both Photoshop CS3 and another Adobe Creative Suite 3 Application, such as Illustrator® CS3, in the same script. ● You can open, save, and rename files using scripts. ● You can copy scripts from one computer to another.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 9 To install a JavaScript in the Scripts menu, place it in the Scripts folder (Photoshop CS3 /Presets /Scripts). The names of the scripts in the Scripts folder, without the file name extension, are displayed in the Scripts menu. Any number of scripts may be installed in the Scripts menu.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 10 a new document, add a layer to an existing document, or change the background color of a layer. Most of the functionality available through the Photoshop CS3 user interface is available through the DOM. A good understanding of the Photoshop CS3 DOM, and how each aspect of the DOM relates to the Photoshop application and its documents will make script writing easier.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 11 The Application class is the root of the Photoshop CS3 object model hierarchy. Scripts must target the appropriate application in order to run correctly. See ‘Targeting and Referencing the Application Object’ on page 20. The Document class is used to make modifications to the document image. By using the Document object you can crop, rotate or flip the canvas, resize the image or canvas, and trim the image.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 12 History State Class The History State 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.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 13 To create this object without using a script: Object Name Description Application The Photoshop CS3 application. Start the Photoshop CS3 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. In Photoshop CS3, choose File > New or File > Open.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 14 To create this object without using a script: (Continued) Object Name Description Color Sampler Represents a color sampler in your document. Choose the Color Sampler Tool, and click in the document. Count Item Represents a counted item in the document. Choose the Count Tool and click in the document. Measurement Scale Represents the measurement scale for your document.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 15 Creating a Sample Hello World Script This section demonstrates a very simple script in each of the three scripting languages for Photoshop CS3. Traditionally, the first thing to accomplish in any programming environment is the display of a "Hello World" message. ➤ Our Hello World scripts will do the following: 1. Open the Photoshop CS3 application. 2. Create a new Document object.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 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 CS3 tell application "Adobe Photoshop CS3" -- Create a new document and art layer.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 17 appRef.Preferences.RulerUnits = originalRulerUnits 2. Save file as a text file with a .vbs file name extension. 3. Double-click the file in Windows Explorer to run the script. The script opens Photoshop CS3. Creating and Running a JavaScript Follow these steps to create and run a JavaScript that displays the text Hello World! in a Photoshop CS3 document.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Basics 18 Note: Photoshop CS3 also supports JavaScript files that use a .js extension. 3. Do either of the following: ● If Photoshop CS3 is already open, choose File > Scripts > Browse, and then navigate to the Presets > Scripts folder and choose your script. ● Start or restart Photoshop CS3, and then choose File > Scripts, and then select your script from the Scripts menu.
3 Scripting Photoshop CS3 This chapter demonstrates several techniques for using the Photoshop Document Object Model (DOM) to create scripts to use specifically with Photoshop CS3. You will also learn how to use the reference manuals and object model browsers to find information about the objects, classes, properties, commands, and even some values (called constants or enumerations) you can use to create AppleScripts, VBScript scripts, and JavaScripts for Photoshop CS3.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 20 Viewing Photoshop CS3’s Type Library (VBS) You can use the VBA editor in Microsoft Word to display the objects and commands available for VBScript in Photoshop CS3. ➤ To view the VBS object library in Microsoft Word: 1. Start Word, and then choose Tools > Macro > Visual Basic Editor. 2. Choose Tools > References, and then select the Adobe Photoshop CS3 Type Library check box and click OK. 3. Choose View > Object Browser. 4.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 21 … 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, do the following to target the application: Dim appRef Set appRef = CreateObject("Photoshop.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 22 set docRef to make new document To create an object other than a document, you must reference the Document object that 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.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 23 JS In JavaScript, you can use the add() method only with the collection name. 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.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 Setting the Active Document The following examples demonstrate how to set the active document.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 25 Setting the Active Layer The following examples demonstrate how to use the current layer (ActiveLayer/activeLayer) property of the Document object to set the active layer. In order to set the active layer for a document, the document itself must be the current document. AS set current layer of current document to layer “Layer 1” of current document Note: By default, Photoshop names the layers “Layer 1”, “Layer2”, etc.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 26 ‘ This example assumes docRef is already the ActiveDocument Dim theChannels theChannels = Array(docRef.Channels(0), docRef.Channels(2)) docRef.ActiveChannels = theChannels Alternatively, select all component channels using the ComponentChannels property of the Document object: appRef.ActiveDocument.ActiveChannels= _ appRef.ActiveDocument.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 27 Specifying File Formats to Open Open Classes Photo CD Open Options Open Options Raw Format Open Options Camera Raw Open Options EPS Open Options PDF Open Options 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 CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 28 VBS Dim appRef Set appRef = CreateObject("Photoshop.Application") 'Remember unit settings and set to values expected by this script Dim originalRulerUnits originalRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = 1 'value of 1 = psPixels 'Create a PDF option object Dim pdfOpenOptionsRef Set pdfOpenOptionsRef = CreateObject("Photoshop.PDFOpenOptions") pdfOpenOptionsRef.AntiAlias = True pdfOpenOptionsRef.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 29 Saving a Document Options for saving documents in Photoshop CS3 are illustrated below. To find out which properties you can specify for a specific file format save option, look up the object that begins with the file format name. For example, to find out about properties for saving an .eps file, do the following: ● In the Adobe Photoshop CS3 AppleScript Scripting Reference, look up the class EPS save options.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 30 Set docRef = appRef.Documents.Add() Set jpgSaveOptions = CreateObject("Photoshop.JPEGSaveOptions") jpgSaveOptions.EmbedColorProfile = True jpgSaveOptions.FormatOptions = 1 'for psStandardBaseline jpgSaveOptions.Matte = 1 'for psNoMatte jpgSaveOptions.Quality = 1 appRef.ActiveDocument.SaveAs "c:\temp\myFile2", _ jpgSaveOptions, True, 2 'for psLowercase JS app.documents.add( 4, 4 ) jpgFile = new File( "/Temp001.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 31 preferences.typeUnits = TypeUnits.PIXELS In the Adobe Photoshop CS3 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer, look up the Preferences object to view all of the settings properties you can use. Additionally, look up the preferences property on the Application object. Allowing or Preventing Dialogs It is important to be able to control dialogs properly from a script.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 32 You use the properties and commands of the Application object to work with Photoshop CS3 functionality and objects such as the following: ● Global Photoshop CS3 settings or preferences, such as unit values or color settings. See ‘Setting Application Preferences’ on page 30. ● Documents—You can add or open documents and set the active document. ‘Opening a Document’ on page 26 and ‘Setting the Active Object’ on page 23.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide ● Crop the image. ● Flip the entire window. ● Restore the original ruler units. Scripting Photoshop CS3 Note: See ‘Setting Application Preferences’ on page 30 for information on ruler units. AS tell application "Adobe Photoshop CS3" set saveUnit to ruler units of settings set ruler units of settings to inch units set duckFile to alias ¬ "OS X 10.4.8 US:Applications:Adobe Photoshop CS3:Samples:Ducky.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 34 JS //save original ruler units, then assign it to inches startRulerUnits = app.preferences.rulerUnits app.preferences.rulerUnits = Units.INCHES //get a reference to the file, and open it var fileRef = new File(app.path + "/samples/ducky.tif") var docRef = app.open(fileRef) //this sample script assumes the ruler units have been set to inches docRef.resizeImage( 4,4 ) docRef.resizeCanvas( 4,4 ) docRef.trim(TrimType.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 VBS Dim appRef Set appRef = CreateObject("Photoshop.Application") ' Create a new art layer at the beginning of the current document Dim docRef Dim layerObj Set docRef = appRef.Documents.Add() Set layerObj = appRef.ActiveDocument.ArtLayers.Add layerObj.Name = "MyBlendLayer" layerObj.BlendMode = 2 'psNormalBlend ' Select all so we can apply a fill to the selection appRef.ActiveDocument.Selection.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 36 end tell VBS Dim appRef Set appRef = CreateObject("Photoshop.Application") 'Make a new document and a first layer in the document appRef.Documents.Add() appRef.ActiveDocument.ArtLayers.Add() ' Get a reference to the first layer in the document Dim layerRef Set layerRef = appRef.ActiveDocument.Layers(1) ' Create a new LayerSet (it will be created at the beginning of the document) Dim newLayerSetRef Set newLayerSetRef = appRef.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 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 CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 38 Linking Layer Objects Scripting also supports linking and unlinking layers. You link layers together so that you can move or transform the layers in a single statement.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 39 VBS docRef.ArtLayers("L1").ApplyStyle "Puzzle (Image)" Look up ApplyStyle as a method of the ArtLayer object in the Adobe Photoshop CS3 Visual Basic Scripting Reference, or in the Visual Basic Object Browser. JS docRef.artLayers["L1"].applyStyle("Puzzle (Image)") Look up applyStyle() as a method of the ArtLayer object in the Adobe Photoshop CS3 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 Determining a Layer’s Kind The following examples use an if statement to check whether an existing layer is a text layer. AS if (kind of layerRef is text layer) then ... endif VBS If layerRef.Kind = 2 Then '2 indicates psTextLayer ... End If 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.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 41 (psParagraphText/TextType.PARAGRAPHTEXT. ) When a new text-object is created, its kind property is automatically set to point text. The text-object properties height, width, and leading are valid only when the text item's kind property is set to paragraph text.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 42 ➤ The following examples assume that the ruler units have been set to pixels and create a selection by: 1. Creating a variable to hold a new document that is 500 x 500 pixels in size. 2. Creating a variable to hold the coordinates that describe the selected area (that is, the Selection object). 3. Adding an array as the selection variable’s value. 4.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 43 JS strokeColor = new solidColor strokeColor.cmyk.cyan = 20 strokeColor.cmyk.magenta = 50 strokeColor.cmyk.yellow = 30 strokeColor.cmyk.black = 0 app.activeDocument.selection.stroke (strokeColor, 2, StrokeLocation.OUTSIDE, ColorBlendMode.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 44 AS fill selection of current document with contents ¬ {class:RGB color, red:255, green:0, blue:0} blend mode ¬ vivid light opacity 25 without preserving transparency 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.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 45 VBS Set chanRef = docRef.Channels.Add chanRef.Name = "My Channel" chanRef.Kind = 3 'psSelectedAreaAlphaChannel docRef.Selection.Store docRef.Channels("My Channel"), 2 'PsSelectionType is 2 (psExtendSelection) JS var chanRef = docRef.channels.add() chanRef.name = "My Channel" chanRef.kind = ChannelType.SELECTEDAREA docRef.selection.store(docRef.channels["My Channel"], SelectionType.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 46 AS set kind of myChannel to selected area channel VBS channelRef.ind = 3 'for psSelectedAreaAlphaChannel 'from the constant value PsChannelType JS channelRef.kind = ChannelType.SELECTEDAREA Using the Document Info Object In Photoshop CS3, you can associate information with a document by choosing File > File Info.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 47 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 opened or created.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 48 Note: This type of script corresponds to selecting Start Application in the Script Events Manager (File > Scripts > Script Events Manager) in the Photoshop CS3 application. Please refer to Photoshop CS3 Help for information on using the Script Events Manager. The make (Add/add) command requires you to specify an event ID to identify the event to set up notification for.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 AS --line #1--it’s a straight line so the coordinates for anchor, left, and --right for each point have the same coordinates tell application "Adobe Photoshop CS3" set ruler units of settings to pixel units set type units of settings to pixel units set docRef to make new document with properties {height:700, width:500, ¬ name:"Snow Cone"} set pathPointInfo1 to {class:path point info, kind:corner point, ¬ anchor:{100, 100}, left dire
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 50 ' stroke it so we can see something myPathItem.StrokePath(2) 'for PsToolType --> 2 (psBrush) JS // create a document to work with var docRef = app.documents.add(5000, 7000, 72, "Simple Line") //line #1--it’s a straight line so the coordinates for anchor, left, and //right //for each point have the same coordinates // First create the array of PathPointInfo objects.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 51 VBS 'create a solidColor array Dim solidColorRef Set solidColorRef = CreateObject("Photoshop.SolidColor") solidColorRef.CMYK.Cyan = 20 solidColorRef.CMYK.Magenta = 90 solidColorRef.CMYK.Yellow = 50 solidColorRef.CMYK.Black = 50 appRef.ForegroundColor = solidColorRef JS //create a solid color array var solidColorRef = new solidColor() solidColorRef.cmyk.cyan = 20 solidColorRef.cmyk.magenta = 90 solidColorRef.cmyk.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 52 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.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 53 AS set myWebSafeColor to web safe color for foreground color VBS Dim myWebSafeColor Set myWebSafeColor = appRef.ForegroundColor.NearestWebColor JS var webSafeColor = new RGBColor() webSafeColor = app.foregroundColor.nearestWebColor Working with Filters To apply a filter in AppleScript, you use the filter command with an option from the class filter options. In VBScript and JavaScript, you use a specific filter method.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 54 JavaScript from your script. See ‘Action Manager’ on page 72 for information on using the Action Manager. Also, see ‘Executing JavaScripts from AS or VBS’ on page 9. Understanding Clipboard Interaction The clipboard commands in Photoshop CS3 operate on ArtLayer, Selection, and Document objects. The commands can be used to operate on objects within a single document, or to move information between documents.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 55 Set newDocRef = appRef.Documents.Add(8, 6, 72, "New Doc") newDocRef.Paste JS //make firstDocument the active document var docRef = app.activeDocument docRef.artLayers["Background"].copy() var newDocRef = app.documents.add(8, 6, 72, "New Doc") newDocRef.paste() Using the Copy Merged Command/Method You can also perform a merged copy to copy all visible layers in the selected area. In AppleScript, you use the copy merged command.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide ● Scripting Photoshop CS3 56 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 CS3 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.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 57 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. Note: The unit values cm units and mm units cannot be used in this way with a corresponding reference to cm or mm. They are not supported by the AppleScript terminology.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 AppleScript Properties VBScript Properties JavaScript Properties offset filter horizontal offset vertical offset HorizontalOffset VerticalOffset horizontalOffset verticalOffset Text Item baseline shift* first line indent* height hyphenation zone* leading* left indent* position right indent* space before* space after* width BaselineShift* FirstLineIndent* Height HyphenationZone* Leading* LeftIndent* Position RightIndent* Spa
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide AppleScript Scripting Photoshop CS3 VBScript 59 JavaScript (Continued) translate (delta x, delta y) Selection.Translate (DeltaX, DeltaY) selection.translate (deltaX, deltaY) translate boundary (delta x, delta y) Selection.TranslateBoun dary (DeltaX, DeltaY) selection.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 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 layer in the document to a separate file. Script Events Manager.jsx Enables and disables notifier objects. Image Processor.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 61 Preference Set to What it does rulers inches Uses inches as the unit of measurement for graphics. 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 CS3 application.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 62 set display dialogs to theStartDisplayDialogs end tell 2. In Photoshop CS3, choose Photoshop > Preferences > Units & Rulers to verify that your preferences have been returned to your original settings. 3. After viewing the document in Photoshop CS3, close the document without saving it. 4. Save the script as HelloWorldDoc. VBS ➤ To work with document preferences: 1. Create the following script.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 63 4. After viewing the document in Photoshop CS3, close the document without saving it. 5. Name the script HelloWorldDoc and save it. JS ➤ To work with document preferences: 1. Create the following script. Note: See ‘Creating and Running a JavaScript’ on page 17 for details on creating a JavaScript. //create and assign variables for default preferences startRulerUnits = app.preferences.rulerUnits startTypeUnits = app.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 64 AS ➤ To create and specify details in a text item: 1. Type the following code into the HelloWorldDoc script immediately before the statements at the end of the file that restore original preferences.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 65 'use the Kind property of the Art Layers class to 'make the layer a text layer newTextLayer.Kind = 2 newTextLayer.TextItem.Contents = helloWorldStr newTextLayer.TextItem.Position = Array(0.75, 1) newTextLayer.TextItem.Size = 36 newTextLayer.TextItem.Color = textColor 2. Run the complete script. Be patient while Photoshop CS3 executes your commands one by one. 3.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 66 Note: Look up the following classes in the Adobe Photoshop CS3 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer to see if you understand how you used them in this script: ● SolidColor ● ArtLayer. Notice that the LayerKind.TEXT value of the kind property uses the LayerKind constant. Constants are always depicted in upper case letters in Photoshop CS3 JavaScripts.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide ● Scripting Photoshop CS3 theDocHeightInPixels indicates the bottom row in the document; that is row whose coordinate is the total number of rows in the document. Note: The value of theDocHeightInPixels is the total number of pixels that determine the vertical dimension of the document. Rows are stacked vertically. ● ● Lower left corner: 0, theDocHeightInPixels ● 0 indicates the left-most column in the document.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 68 Note: Look up the following classes in the Adobe Photoshop CS3 AppleScript Scripting Reference, or in the Photoshop CS3 AppleScript Dictionary to see if you understand how you used them in this script: ● wave filter class ● art layer class ● ● rasterize command ● filter command document class: select command, combination type parameter VBS ➤ To select an area and apply a wave filter to it: 1.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 69 JS ➤ To select an area and apply a wave filter to it: 1.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 70 set theSelRegion to {{theDocWidthInPixels / 2, 0},¬ {theDocWidthInPixels, 0}, ¬ {theDocWidthInPixels, theDocHeightInPixels}, ¬ {theDocWidthInPixels / 2, theDocHeightInPixels}, ¬ {theDocWidthInPixels / 2, 0}} select theDocRef region theSelRegion combination type replaced filter current layer of theDocRef using motion blur ¬ with options {class:motion blur, angle:45, radius:5} deselect theDocRef 2. Choose Run to run the script.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Scripting Photoshop CS3 71 2. Save the script, and then open Photoshop CS3 and select the script from the Scripts menu (choose File > Script > HelloWorldDoc).
4 Action Manager Photoshop CS3 actions allow you to save time by automating repetitive tasks. You create and run actions in the application interface using the Actions palette. You can also manage actions in scripts using a utility called the Action Manager. The Action Manager allows you to write scripts that target Photoshop CS3 functionality that is not otherwise accessible in the scripting interface, such as third party plug-ins and filters.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 73 ➤ To uninstall the ScriptListener: 1. Close Photoshop CS3. 2. Verify that a copy of the file ScriptListener.8li still exists in the ..\Adobe Photoshop CS3\Scripting Guide\Utilities folder. 3. Delete the file ScriptListener.8li from the following location: ..\Adobe Photoshop CS\Plug-Ins\Automate 4. Delete the log files ScriptingListenerJS.log and ScriptingListenerVB.log from your desktop.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide ● Action Manager 74 On Mac OS, the log files are on the desktop. Using the Action Manager from JavaScript The section demonstrates how to use the contents of the ScriptingListenerJS.log log to create your script. Before you begin this section, you need have already recorded an action. The example in this section assumes you have followed the instructions in ‘Recording a Script using ScriptListener’ on page 73.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 75 desc4.putInteger( id20, angle ); var id21 = charIDToTypeID( "Hght" ); desc4.putInteger( id21, height ); var id22 = charIDToTypeID( "Amnt" ); desc7.putInteger( id22, amount ); executeAction( id19, desc4 ,DialogModes.NO); } 5. To use a JavaScript to apply the Emboss filter to a document, include the emboss function in the JavaScript and call the function with the desired parameters.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 76 DIM id9 id9 = objApp.CharIDToTypeID( "Embs" ) DIM desc4 SET desc4 = CreateObject( "Photoshop.ActionDescriptor" ) DIM id10 id10 = objApp.CharIDToTypeID( "Angl" ) Call desc4.PutInteger( id10, 135 ) DIM id11 id11 = objApp.CharIDToTypeID( "Hght" ) Call desc4.PutInteger( id11, 3 ) DIM id12 id12 = objApp.CharIDToTypeID( "Amnt" ) Call desc4.PutInteger( id12, 100 ) Call objApp.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 77 id9 = objApp.CharIDToTypeID( "Embs" ) DIM desc4 SET desc4 = CreateObject( "Photoshop.ActionDescriptor" ) DIM id10 id10 = objApp.CharIDToTypeID( "Angl" ) Call desc4.PutInteger( id10, angle ) DIM id11 id11 = objApp.CharIDToTypeID( "Hght" ) Call desc4.PutInteger( id11, height ) DIM id12 id12 = objApp.CharIDToTypeID( "Amnt" ) Call desc4.PutInteger( id12, amount ) Call objApp.ExecuteAction( id9, desc4, dialogMode ) End Function 5.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 78 Running JavaScript-based Action Manager code from VBScript You can also access JavaScript-based Action Manager code from a VBScript using the DoJavaScriptFile method. Use the VBscript object browser for more information on the Application.DoJavaScriptFile method. ➤ To execute JavaScript-based Action Manager code from a VBScript: 1. Follow steps 1-4 in ‘Using the Action Manager from JavaScript’ on page 74.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 79 desc7.putInteger( id34, height ); var id35 = charIDToTypeID( "Amnt" ); desc7.putInteger( id35, amount ); executeAction( id32, desc7 ); } 2. At the end of the file emboss.jsx, add the following line of JavaScript code, which executes the emboss function with arguments passed to it from an external invocation. See Introduction to Scripting for more information about passing arguments from a AppleScript to a JavaScript.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 80 5. You can now use this event ID to set up event notification on Open Document from your scripts. In JavaScript, for example: var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx") app.notifiers.add( "Opn ", eventFile) ➤ Finding the event ID and class ID for the “New” event 1. Make sure that the ScriptListener plug in is installed. 2. Open Photoshop CS3, then create a new document using File > New. 3.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Action Manager 81 desc9.putEnumerated( id36, id37, id38 ); var id39 = charIDToTypeID( "Clr " ); var desc10 = new ActionDescriptor(); var id40 = charIDToTypeID( "Rd " ); desc10.putDouble( id40, 255.000000 ); var id41 = charIDToTypeID( "Grn " ); desc10.putDouble( id41, 0.000000 ); var id42 = charIDToTypeID( "Bl " ); desc10.putDouble( id42, 0.000000 ); var id43 = charIDToTypeID( "RGBC" ); desc9.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Index A Action Manager defined 72 running JavaScript code from AppleScript 78 running JavaScript code from VBScript 78 scripting objects 73 using from JavaScript 74 using from VBScript 75 actions vs.
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide script files 8 files inferring format 26 opening 26 opening using specific settings 27 saving 29 specifying format 27 filters additional 53 applying motionblur 69 applying wave 66–69 making scriptable 73 working with 53 H Hello World script 15–18 hex color values, setting 51 hierarchy 10 History State object defined 12 purging 47 relationship to user interface 13 reverting 47 using 46 history states defined 46 I images, changing composition 11 J JavaScrip
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide working with 60 Preferences object defined 12 relationship to user interface 13 properties conventions 5 finding 19 R ruler units defined 55 setting 59 value usage 57 values 56 S Save options classes 14 saving documents 29 Script Editor using 15 scripting languages example scripts 15 supported 8 ScriptListener finding class IDs 79 finding event IDs 79 installing 72 log files 72 recording scripts 73 uninstalling 73 scripts advanced 60 capabilities 7 creatin
Photoshop CS3 Adobe Photoshop CS3 Scripting Guide Index 85