Adobe 23101335 - Photoshop - PC Manual
Adobe 23101335 - Photoshop - PC Manual

Adobe 23101335 - Photoshop - PC Manual

Scripting guide
Hide thumbs Also See for 23101335 - Photoshop - PC:

Advertisement

Photoshop 7.0
Scripting Guide
c
b b
ADOBE SYSTEMS INCORPORATED
Corporate Headquarters
345 Park Avenue
San Jose, CA 95110-2704
(408) 536-6000
http://partners.adobe.com
March 2002

Advertisement

Table of Contents
loading

Summary of Contents for Adobe 23101335 - Photoshop - PC

  • Page 1 Photoshop 7.0 Scripting Guide ADOBE SYSTEMS INCORPORATED Corporate Headquarters 345 Park Avenue San Jose, CA 95110-2704 (408) 536-6000 http://partners.adobe.com March 2002...
  • Page 2 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 countries.
  • Page 3: Table Of Contents

    Table of contents Chapter 1 Introduction ......5 1.1 About this manual ........5 1.2 What is scripting? .
  • Page 4 Table of contents 3.8 Document object ........54 3.9 Layer objects .
  • Page 5: Chapter 1 Introduction

    Introduction 1.1 About this manual This manual provides an introduction to scripting Adobe Photoshop 7.0 on Mac OS and ® Windows . Chapter one covers the basic conventions used in this manual and provides an overview of requirements for scripting Photoshop.
  • Page 6: What Is Scripting

    Introduction What is scripting? 1.2 What is scripting? A script is a series of commands that tells Photoshop to perform a set of specified actions. These actions can be simple, and affect only a single object in the current document, or complex and affect many objects in a Photoshop document.
  • Page 7: Javascript

    Introduction JavaScript 1.5.1 Mac Any system that runs Photoshop 7.0 will support scripting. You will also need AppleScript and a script editor installed. AppleScript and the Script Editor application from Apple are included with the Mac OS. For Mac OS 9.X the default location for the Script Editor application is the Apple Extras folder.
  • Page 8: Legacy Com Scripting

    Introduction Legacy COM scripting the facilities to directly address other applications. For example, you cannot easily write a JavaScript to manage workflows involving Photoshop and a database management program. AppleScript and Visual Basic are only offered on their respective platforms. However, you can write scripts in those languages to control multiple applications.
  • Page 9: Chapter 2 Scripting Basics

    Scripting basics 2.1 Documents as objects If you use Photoshop, then you create documents, layers, channels and design elements and can think of a Photoshop document as a series of layers and channels — or objects. Automating Photoshop with scripting uses the same object-oriented way of thinking. The heart of a scriptable application is the object model.
  • Page 10 Scripting basics Object model concepts 2.2.2 Object inheritance Object classes may also “inherit,” or share, the properties of a parent, or superclass. When a class inherits properties, we call that class a child, or subclass of the class from which it inherits properties.
  • Page 11: Documenting Scripts

    Scripting basics Documenting scripts When you identify an object in this fashion, you’re creating an object reference. While AppleScript, Visual Basic and JavaScript use different syntax for object references, each gives the script a way of finding the object you want. 2.3 Documenting scripts Use comments within your scripts to explain what procedures are taking place.
  • Page 12: Values

    Scripting basics Values Visual Basic In Visual Basic, you can break a long statement into multiple lines in the Code window by using the line continuation character, which is a space followed by an underscore ( _). 2.4 Values Values are the data your scripts use to do their work. Most of the time, the values used in your scripts will be numbers or text.
  • Page 13 Scripting basics Values Visual Basic Values ABLE Value type: What it is: Example: Boolean Logical true or false True Long Whole numbers (no decimal points). Longs can be positive or negative. Double A number which may 13.9972 contain a decimal point. String A series of text characters.
  • Page 14: Variables

    Scripting basics Variables 2.5 Variables Variables are containers for data. A variable might contain a number, a string, a list (or array), or an object reference. Variables have names, and you refer to a variable by its name. To put data into a variable, assign the data to the variable.
  • Page 15 Scripting basics Variables 2.5.2 Using variables to store references Variables can also be used to store references to objects. In AppleScript, a reference is returned when you create a new object in an Photoshop document as shown below: set thisLayer to make new art layer in current document Or you can fill the variable with a reference to an existing object: set thisLayer to art layer 1 of current document Visual Basic works similarly, however, there is an important distinction to note.
  • Page 16: Operators

    Scripting basics Operators 2.6 Operators Operators perform calculations (addition, subtraction, multiplication, and division) on variables or values and return a result. For example: docWidth/2 would return a value equal to half of the content of the variable docWidth . So if docWidth contained the number 20.5, the value returned would be 10.25 .
  • Page 17: Commands And Methods

    The following examples check the number of currently open documents. If no documents are open, the scripts display a messages in a dialog box. tell application "Adobe Photoshop 7.0" set documentCount to count every document if documentCount = 0 then display dialog "No Photoshop documents are open!"...
  • Page 18: Control Structures

    Scripting basics Commands and methods Private Sub Command1_Click() Dim documentCount As long Dim appRef As New Photoshop.Application documentCount = appRef.Documents.Count If documentCount = 0 Then MsgBox "No Photoshop documents are open!" End If End Sub var documentCount = documents.length; if (documentCount == 0) alert("There are no Photoshop documents open");...
  • Page 19 Scripting basics Commands and methods A more complicated type of control structure includes conditional logic, so that it loops while or until some condition is true or false. set flag to false repeat until flag = true set flag to button returned of (display dialog "Quit?" ¬ buttons {"Yes", "No"}) = "Yes"...
  • Page 20: Handlers, Subroutines And Functions

    Scripting basics Handlers, subroutines and functions var flag = false; while (flag == false) flag = confirm("Are you sure?"); var flag = false; flag = confirm("Are you sure?"); while (flag == false); 2.8 Handlers, subroutines and functions Subroutines, or handlers (in AppleScript) and functions (in JavaScript), are scripting modules you can refer to from within your script.
  • Page 21: The Scripts Menu

    Scripting basics The Scripts menu Private Sub ScriptSample_Click(Index As Integer) result = DoConfirm("Are you sure?") MsgBox (result) End Sub Function DoConfirm(prompt) As Boolean buttonPressed = MsgBox(prompt, vbYesNo) DoConfirm = (buttonPressed = vbYes) End Function var theResult = DoConfirm( "Are you sure?" ); alert(theResult);...
  • Page 22 Scripting basics The Scripts menu “Run Script” button will change to “Debug Script.” Clicking this button will execute the JavaScript in a debug window. See 2.10.3, “JavaScript Debugging” on page 26 for more information. There is also a “Browse...” button in the Scripts dialog. When this button is clicked, a file navigation dialog will be presented.
  • Page 23: Testing And Troubleshooting

    Scripting basics Testing and troubleshooting 2.10 Testing and troubleshooting The scripting environments provide tools for monitoring the progress of your script while it is running — which make it easier for you to track down any problems your script might be encountering or causing.
  • Page 24 Scripting basics Testing and troubleshooting You can display the contents of one or more variables in the log window by using the log command. log {myVariable, otherVariable} In addition, the Result window (choose Controls > Show Result) will display the value from the last script statement evaluated.
  • Page 25 Scripting basics Testing and troubleshooting 2.10.2 Visual Basic debugging In Visual Basic, you can stop your script at any point, or step through your script one line at a time. To stop your script at a particular line, select that line in your script and choose “Debug > Toggle Breakpoint”.
  • Page 26 Scripting basics Testing and troubleshooting 2.10.3 JavaScript Debugging This section describes the information and controls that the main Script Debugger window provides. In Photoshop you can use the JavaScript Debugger Window to step through your JavaScript code. JavaScript can be executed in two different ways: from the UI via the “Scripts...” menu and from AppleScript of VisualBasic via the do javascript methods.
  • Page 27 Scripting basics Testing and troubleshooting Viewing Debug Information The Photoshop Script Debugger window provides three informational views that Figure 2.1 depicts. Script Debugger window IGURE Stack Trace view Debug Output view JavaScript Source view Script Breakpoints Display Resume (R) Pause (P) Step Out (U) Step Into(T) Stop (K)
  • Page 28 Scripting basics Testing and troubleshooting Controlling Code Execution in the Script Debugger Window This section describes the buttons that control the execution of code when the Script Debugger window is active. Most of these buttons also provide a keyboard shortcut available as a Ctrl- key combination on Windows platforms or a Cmd- key combination on Mac OS platforms.
  • Page 29 Scripting basics Testing and troubleshooting Script Breakpoints Display (no keyboard shortcut) Clicking this button displays the Script Breakpoints Window shown in Figure 2.2. Using the JavaScript Command Line Entry Field You can use the Script Debugger window’s command line entry field to enter and execute Javascript code interactively within a specified stack scope.
  • Page 30 Scripting basics Testing and troubleshooting Script Breakpoints Window This section describes the information and controls that the Script Breakpoints window provides. Display of the Script Breakpoints window is controlled by the Script Breakpoints button in the main script debugger windown described on page Script Breakpoints window IGURE...
  • Page 31: Error Handling

    --Store a reference to the document with the name "My Document" --If it does not exist, display an error message tell application "Adobe Photoshop 7.0" set docRef to document "My Document" display dialog "Found 'My Document' " on error display dialog "Couldn't locate document 'My Document'"...
  • Page 32 Scripting basics Testing and troubleshooting for (i = 0; i < documents.length; ++i) var myName = documents[i].name; alert(myName); catch(someError) alert( "JavaScript error occured. Message = " + someError ); Photoshop 7.0 Scripting Guide...
  • Page 33: Chapter 3 Scripting Photoshop

    For example, the following script would modify the color profile of all open documents named “MyDocument.” tell application "Adobe Photoshop 7.0" set color profile kind of document "MyDocument" to none end tell...
  • Page 34: Viewing Photoshop Objects, Commands And Methods

    Scripting Photoshop Viewing Photoshop objects, commands and methods 3.2 Viewing Photoshop objects, commands and methods This section shows how to view Photoshop’s objects, commands and properties in AppleScript and Visual Basic editors. JavaScript does not include an object browser. 3.2.1 Viewing Photoshop’s AppleScript dictionary 1.
  • Page 35 VBA application, choose “Tools > References.” 2. Turn on the “Adobe Photoshop 7.0 Object Library” option from the list of available references and click the “OK” button. If the library does not appear in the list of available references, then Scripting Support is not installed properly.
  • Page 36: Your First Photoshop Script

    -- Sample script to create a new text item and change its -- contents. tell application "Adobe Photoshop 7.0" -- 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.
  • Page 37: Visual Basic

    Your first Photoshop script 3.3.2 Visual Basic 1. Start Visual Basic and create a new project. Add the “Adobe Photoshop 7.0 Object Library” reference to the project, as shown earlier. If you are using a built-in editor in a VBA application, skip to step 4.
  • Page 38 Scripting Photoshop Your first Photoshop script 4. Enter the following code. The lines preceded by ' (single quotes) are comments, and will be ignored by the scripting system. They’re included to describe the operation of the script. As you look through the script, you’ll see how to create, then address each object. Private Sub Command1_Click() ' Hello World Script Dim appRef As New Photoshop.Application...
  • Page 39 Scripting Photoshop Your first Photoshop script 3.3.3 VBScript You don't need to use Visual Basic to run scripts on Windows. Another way to script Photoshop is to use a VBA editor (such as the one that is included in Microsoft Word) or to use Windows Scripting Host.
  • Page 40 Scripting Photoshop Your first Photoshop script Here’s an example VBScript: ' Hello World Script Dim appRef Set appRef = CreateObject( "Photoshop.Application" ) ' Remember current unit settings and then set units to ' the value expected by this script Dim originalRulerUnits originalRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = 2 ' Create a new 4x4 inch document and assign it to a variable.
  • Page 41 Scripting Photoshop Your first Photoshop script 3.3.4 JavaScript // Hello Word Script // Remember current unit settings and then set units to // the value expected by this script var originalUnit = preferences.rulerUnits; preferences.rulerUnits = Units.INCHES; // Create a new 4x4 inch document and assign it to a variable var docRef = documents.add( 4, 4 );...
  • Page 42: Object References

    2nd layer. Therefore, any references made to layer 1 of current document will now refer to the new layer. Consider the following sample script: tell application "Adobe Photoshop 7.0" activate set newDocument to make new document with properties ¬...
  • Page 43: Visual Basic And Javascript

    Scripting Photoshop Object references 3.4.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.
  • Page 44: Working With Units

    Scripting Photoshop Working with units 3.5 Working with units Photoshop provides two rulers for use when working on a document — a graphics ruler used for most graphical layout measurements and a type ruler which is active when using the type tool.
  • Page 45 Scripting Photoshop Working with units The values returned for a Photoshop property which used units will be returned as a value of the current 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.
  • Page 46 Scripting Photoshop Working with units Special unit value types The unit values used by Photoshop Scripting Support are length units, representing values of linear measurement. Support is also included for pixel and percent unit values. These two unit value types are not, strictly speaking, length values but are included because they are used extensively by Photoshop for many operations and values.
  • Page 47 Scripting Photoshop Working with units Object Properties ABLE AppleScript Visual Basic JavaScript Object Properties Properties Properties Text Item baseline shift* BaselineShift* baselineShift* first line indent* FirstLineIndent* firstLineIndent* height Height height hyphenation zone* HyphenationZone* hyphenationZone* leading* Leading* leading* left indent* LeftIndent* leftIndent* position Position...
  • Page 48: Executing Javascripts From As Or Vb

    Scripting Photoshop Executing JavaScripts from AS or VB Command Parameters ABLE AppleScript Visual Basic JavaScript translate boundary Selection.TranslateBoundary selection.translateBoundary (delta x, delta y) (DeltaX, DeltaY) (deltaX, deltaY) 3.5.3 Changing ruler and type units The unit type settings of the two Photoshop rulers control how numbers are interpreted when dealing with properties and parameters that support unit values.
  • Page 49 ( i = 0; i < arguments.length; ++i ) alert( arguments[i].toString() ) To pass arguments from AppleScript try this: tell application "Adobe Photoshop 7.0" make new document do javascript (alias <a path to the JavaScript shown above>) ¬ with arguments {1, "test text", (file <a path to a file>),¬...
  • Page 50: The Application Object

    To target the Photoshop application in AppleScript, you must use a tell..end tell block. By enclosing your Photoshop commands in the following statement, AppleScript will understand you are targeting Photoshop. tell application "Adobe Photoshop 7.0" … end tell Photoshop 7.0 Scripting Guide...
  • Page 51 Scripting Photoshop The Application object In Visual Basic or VBScript, you create and use a reference to the Application. Typically, you would write: Set appRef = CreateObject("Photoshop.Application") If using VB, this can also be done by writing: Set appRef = New Photoshop.Application In JavaScript, there is no application object and therefore, all properties and methods of the application are accessible without any qualification.
  • Page 52 Scripting Photoshop The Application object Display dialogs It is important to be able to control dialogs 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.
  • Page 53 Photo CD Open Options (PhotoCDOpenOptions/PhotoCDOpenOptions) raw format Options (RawFormatOpenOptions/RawFormatOpenOptions) The following example shows how to open a generic PDF document. tell application "Adobe Photoshop 7.0" set myFilePath to alias < a file path > open myFilePath as PDF with options ¬...
  • Page 54: Document Object

    Scripting Photoshop Document object pdfOpenOptionsRef.Width = 200 pdfOpenOptionsRef.mode = psOpenRGB pdfOpenOptionsRef.Resolution = 72 pdfOpenOptionsRef.ConstrainProportions = False 'Now open the file Dim docRef As Photoshop.Document Set docRef = appRef.Open(< a file path>, pdfOpenOptionsRef) 'Restore unit setting appRef.Preferences.RulerUnits = originalRulerUnits // Set the ruler units to pixels var originalRulerUnits = preferences.rulerUnits;...
  • Page 55 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. tell application "Adobe Photoshop 7.0" make new document set myOptions to {class:JPEG save options, ¬...
  • Page 56: Document Information

    "http://www.adobe.com" Set docInfoRef = docRef.Info docInfoRef.Copyrighted = psCopyrightedWork docInfoRef.OwnerUrl = "http://www.adobe.com"...
  • Page 57: Document Manipulation

    Scripting Photoshop Document object 3.8.3 Document manipulation The Document object 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. Because unit values are passed in when resizing an image, it is recommended that you first set your ruler units prior to resizing.
  • Page 58: Layer Objects

    The following examples show how to create an art layer filled with red at the beginning of the current document tell application "Adobe Photoshop 7.0" make new art layer at beginning of current document ¬ with properties {name:"MyBlendLayer", blend mode:normal} select all current document fill selection of current document with contents ¬...
  • Page 59 Scripting Photoshop Layer objects Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application") ' Create a new art layer at the beginning of the current document Dim docRef As Photoshop.Document Dim layerObj As Photoshop.ArtLayer Set docRef = appRef.ActiveDocument Set layerObj = appRef.ActiveDocument.ArtLayers.Add layerObj.Name = "MyBlendLayer"...
  • Page 60 Layer objects The following examples show how to create a layer set after the first layer in the current document: tell application "Adobe Photoshop 7.0" make new layer set after layer 1 of current document end tell Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application")
  • Page 61 Scripting Photoshop Layer objects 3.9.1 Setting the Active layer Before attempting to manipulate a layer you must first select it. You can do this by setting the current layer (ActiveLayer/activeLayer) to the one you want to manipulate. set current layer of current document to layer "Layer 1" of ¬ current document docRef.ActiveLayer = docRef.Layers("Layer 1") docRef.activeLayer = docRef.layers["Layer 1"];...
  • Page 62 Scripting Photoshop Layer objects In Visual Basic and JavaScript you’ll have to duplicate the layer and then move it. Here’s how: Set layerSetRef = docRef.LayerSets.Add Set layerRef = docRef.ArtLayers(1).Duplicate layerRef.MoveToEnd layerSetRef var layerSetRef = docRef.layerSets.add(); var layerRef = docRef.artLayers[0].duplicate(); layerRef.moveToEnd (layerSetRef); 3.9.3 Linking layers Scripting also supports linking and unlinking layers.
  • Page 63 Scripting Photoshop Layer objects 3.9.4 Applying styles to layers Styles can be applied to layers from your scripts. The styles correspond directly to the styles in the Photoshop Styles palette and are referenced by their literal string name. Here is an example of how to set a layer style to the layer named “L1.”...
  • Page 64: Text Item Object

    Scripting Photoshop Text item object 3.10 Text item object In Photoshop, the Text object is a property of the art layer. To create a new text layer, you must create a new art layer and then set the art layer's kind (Kind/kind) property to text layer (psTextLayer/ LayerKind.TEXT) .
  • Page 65 Scripting Photoshop Text item object docRef.artLayers["my text"].textItem.justification = Justification.RIGHT; The text item object has a kind property, which can be set to either point IMPO R TAN T: text (psPointText/TextType.POINTTEXT ) or paragraph text (psParagraphText/TextType.PARAGRAPHTEXT ). When a new text item is created, its kind property is automatically set to point text .
  • Page 66 Scripting Photoshop Text item object 3.10.2 Setting text stroke colors Setting the stroke color in AppleScript is a bit different then setting it in Visual Basic or JavaScript. To set the stroke color in AppleScript, use one of the color classes: CMYK color, gray color, HSB color, Lab color, or RGB color.
  • Page 67: Selections

    Scripting Photoshop Selections 5. Create a script to get the font name of the text. An example JavaScript is below: var textLayer = activeDocument.artLayers[0]; if (textLayer.kind == LayerKind.TEXT) alert(textLayer.textItem.font); 6. The name that is displayed in the alert dialog is the PostScript name of the font. Use this name to set the font of your text For example, the above script returned the name “ArialMT.”...
  • Page 68: Defining Selections

    Scripting Photoshop Selections set current layer of current document to layer "Layer 1" of ¬ current document docRef.ActiveLayer = docRef.Layers("Layer 1") docRef.activeLayer = docRef.layers["Layer 1"]; See section 3.9.1, “Setting the Active layer” on page 61 for more information. 3.11.1 Defining selections To create a new selection, use the select method with a type of replaced (psReplaceSelection/SelectionType.REPLACED) .
  • Page 69: Stroking The Selection Border

    Scripting Photoshop Selections Dim appRef As New Photoshop.Application 'remember unit settings; and set to values expected by this script Dim originalRulerUnits As Photoshop.PsUnits originalRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = psPixels 'get selection and replace it Dim docRef As Photoshop.Document Set docRef = appRef.ActiveDocument docRef.Selection.Select Array(Array(50, 60), Array(150, 60), _ Array(150, 120), Array(50, 120)), Type:=psReplaceSelection 'restore unit setting...
  • Page 70 Scripting Photoshop Selections selRef.Stroke strokeColor, Width:=5, Location:=psInsideStroke, _ mode:=psVividLightBlend, Opacity:=75, _ PreserveTransparency:=False activeDocument.selection.stroke (strokeColor, 2, StrokeLocation.OUTSIDE, ColorBlendMode.VIVIDLIGHT, 75, false); The transpareny parameter cannot be used for background layers. IMPO R TAN T: 3.11.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.
  • Page 71: Filling A Selection

    Scripting Photoshop Selections Dim originalRulerUnits As Photoshop.PsUnits 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 // remember unit settings; and set to pixels var originalRulerUnits = preferences.rulerUnits;...
  • Page 72 Scripting Photoshop Selections var fillColor = new SolidColor(); fillColor.rgb.red = 255; fillColor.rgb.green = 0; fillColor.rgb.blue = 0; activeDocument.selection.fill( fillColor, ColorBlendMode.VIVIDLIGHT, 25, false); To fill the current selection with the 10th item in the history state, you would write: fill selection of current document with contents history state 10 ¬ of current document selRef.Fill docRef.HistoryStates(10) selRef.fill( activeDocument.historyStates[9]);...
  • Page 73 Scripting Photoshop Selections 3.11.7 Loading and storing selections Scripting Support exposes the functionality to store and load selections. Selections get stored into channels and loaded from channels.The following examples will store the current selection into a channel named “My Channel” and extend the selection with any selection that is currently in that channel.
  • Page 74: Working With Filters

    Scripting Photoshop Working with Filters 3.12 Working with Filters To apply a filter, use the layer's filter command for AppleScript or the ApplyXXX/applyXXX methods for Visual Basic and JavaScript. The following examples apply the Gaussian blur filter to the active layer. filter current layer of current document using Gaussian blur ¬...
  • Page 75: Channel Object

    Scripting Photoshop Channel object appRef.ActiveDocument.ActiveChannels= _ appRef.ActiveDocument.ComponentChannels activeDocument.activeChannels = activeDocument.componentChannels; 3.12.2 Other filters If the filter type that you want to use on your layer is not part of the scripting interface, you can also 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.
  • Page 76: Setting The Active Channel

    Scripting Photoshop Channel object 3.13.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.
  • Page 77: Color Objects

    Scripting Photoshop Color objects 3.14 Color objects From scripting you can use the same range of colors that are available from the Photoshop user interface. Each has its own set of properties, which are specific to the color. For example, the RGB color class contains three properties —...
  • Page 78 Scripting Photoshop Color objects solidColor.CMYK.Black = 50 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 model.
  • Page 79: Comparing Colors

    Scripting Photoshop Color objects The examples below show how to convert the foreground color to a Lab color. -- Convert foreground application color to Lab set myLabColor to convert color foreground color to Lab ' Get the foreground color as Lab Dim myLabColor As Photoshop.LabColor Set myLabColor = appRef.ForegroundColor.Lab // Get the Lab color from the foreground color.
  • Page 80: History Object

    Scripting Photoshop History object 3.15 History object Photoshop keeps a history of the actions that affect the appearance of documents. Each entry in the Photoshop History palette is considered a “History State.” These states are accessable 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.
  • Page 81: Clipboard Interaction

    Scripting Photoshop Clipboard interaction Reverting back to a previous history state does not remove any latter states IMPO R TAN T: from the history collection. Use the Purge command to remove latter states from the history collection as shown below: purge history caches appRef.Purge( psHistoryCaches) purge( PurgeTarget.HISTORYCACHES );...
  • Page 82 Scripting Photoshop Clipboard interaction 3.16.2 Copy merged You can also perform a merged copy. This will make a copy of all visible layers in the selected area. In AppleScript, use the copy merged command. activate select all of current document copy merged selection of current document In VB and JS, pass true for the Merged parameter of the Copy methods.
  • Page 83 Scripting Photoshop Clipboard interaction 3.16.4 Paste The paste command can be used on any open document, and operates on 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.
  • Page 84: Action Manager Scripting

    Scripting Photoshop Action Manager scripting 3.17 Action Manager scripting The Action Manager allows you to write scripts that target functionality that is not otherwise accessible. You are able to script third party plug-ins, filters, and other tasks that are not otherwise included in the scripting interface.
  • Page 85 Scripting Photoshop Action Manager scripting When the ScriptingListener is installed, running the Emboss filter is recorded to a file called “ScriptingListenerJS.log” (see above for location of this file on the various platforms). Open the “ScriptingListenerJS.log” file. At the end of the file you will see something like the following.
  • Page 86 Scripting Photoshop Action Manager scripting desc7.putInteger( id33, angle ); var id34 = charIDToTypeID( "Hght" ); desc7.putInteger( id34, height ); var id35 = charIDToTypeID( "Amnt" ); desc7.putInteger( id35, amount ); executeAction( id32, desc7 ); // Then call emboss with desired parameters emboss( 75, 2, 89 );...
  • Page 87 Scripting Photoshop Action Manager scripting Action Manager code. The next section covers how to run VBScript based Action Manager code. To access JavaScript code from VBScript, you must use the “DoJavaScriptFile” command and provide specific settings in the “arguments” parameter. Save the following script in a file called “C:\Emboss.js”...
  • Page 88 Scripting Photoshop Action Manager scripting DIM id21 id21 = objApp.CharIDToTypeID( "Hght" ) Call desc4.PutInteger( id21, 3 ) DIM id22 id22 = objApp.CharIDToTypeID( "Amnt" ) Call desc4.PutInteger( id22, 100 ) Call objApp.ExecuteAction( id19, desc4 ) To make Emboss scriptable you must identify the filter values that you entered (135, 3 and 100).
  • Page 89 Index Comments in scripts 11 AppleScript 11 Action Manager 84 JavaScript 11 AppleScript dictionary 34 Visual Basic 11 AppleScript Values 12 Condition field 30 Application object 50 Conditional statements 17 display dialogs 52 Control structures 18 opening a document 52 Conventions in this guide 5 preferences 51 cross-application capability 8...
  • Page 90 Index Object inheritance 10 Object reference 10, 12, 13 handlers 20 Object references 42 History object 80 AppleScript 42 Visual Basic and JavaScript 43 Opening a document 52 Operators 16 Integer 12 Other scripting languages 8 Inverting selections 70 Photoshop actions 6 JavaScript Photoshop object model 9 Scripts folder 21...
  • Page 91 Index Stroking the selection border 69 Naming variables 15 subroutines 20 Viewing Photoshop objects, commands and methods 34 superclass 10 AppleScript dictionary 34 System requirements 6 Viewing Photoshop ojects, commands and methods JavaScript 7 Visual Basic type library 35 Mac 7 Visual Basic Windows 7 Object Browser 35...

This manual is also suitable for:

Photoshop 7.0

Table of Contents