Adobe 23101764 Scripting Guide

Adobe 23101764 - Photoshop CS - PC Manual

Adobe 23101764 manual content summary:

  • Adobe 23101764 | Scripting Guide - Page 1
    Photoshop CS bc Scripting Guide ADOBE SYSTEMS INCORPORATED Corporate Headquarters 345 Park Avenue San Jose, CA 95110-2704 (408) 536-6000 http://partners.adobe.com October 2003
  • Adobe 23101764 | Scripting Guide - Page 2
    Adobe Photoshop Scripting Guide Copyright 1991-2003 Adobe Systems Incorporated. All rights reserved. The information in this document is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems
  • Adobe 23101764 | Scripting Guide - Page 3
    of contents Chapter 1 Introduction 1 1.1 About this manual 1 1.2 What is scripting 2 1.3 Why use Photoshop 31 3.1 Photoshop scripting guidelines 31 3.2 Viewing Photoshop objects, commands and methods 31 3.3 Your first Photoshop script 35 3.4 Advanced Scripting 41 Photoshop CS Scripting Guide
  • Adobe 23101764 | Scripting Guide - Page 4
    77 3.12 Selections 81 3.13 Working with Filters 88 3.14 Channel object 89 3.15 Color objects 91 3.16 History object 94 3.17 Clipboard interaction 96 Photoshop CS Scripting Guide iv
  • Adobe 23101764 | Scripting Guide - Page 5
    1.1 About this manual This manual provides an introduction to scripting Adobe® Photoshop® CS on Mac OS and Windows®. Chapter one covers the basic conventions used in this manual and provides an overview of requirements for scripting Photoshop. Chapter two covers the Photoshop object model as
  • Adobe 23101764 | Scripting Guide - Page 6
    tool to streamline tasks that might be too time consuming to do manually. For example, you could write a script to generate a number of localized versions of a particular image; or to gather information about the various color profiles used by a collection of images. Photoshop CS Scripting Guide 2
  • Adobe 23101764 | Scripting Guide - Page 7
    such as those described in this manual and move on to more actions? Photoshop actions are different from scripts. A Photoshop action is "play" an action, Photoshop performs all of the recorded Photoshop and Illustrator in the same script. The Actions palette, invoked under the Window menu, supports
  • Adobe 23101764 | Scripting Guide - Page 8
    We use the Script Editor from Apple in this manual. For more information on the AppleScript scripting environment, see Section 3.2.1, "Viewing Photoshop's AppleScript dictionary 1.5.2 Windows Any Windows system that runs Photoshop CS will support scripting. You will also need either the Windows
  • Adobe 23101764 | Scripting Guide - Page 9
    Visual Basic on Windows. You may also use other scripting languages when working with Photoshop. On Mac OS, any language which lets you send Apple events can be used to script Photoshop. On Windows, any language which is COM aware can be used to script Photoshop. Photoshop CS Scripting Guide 5
  • Adobe 23101764 | Scripting Guide - Page 10
    Legacy COM scripting 1.8 Legacy COM scripting Photoshop CS supports legacy COM scripting as long as you modify the way that you refer to the Photoshop application object in your scripts. For example, instead of saying: Set appRef = CreateObject("Photoshop.Application") you must change the above code
  • Adobe 23101764 | Scripting Guide - Page 11
    for presentation as a slide show. Photoshop CS has this feature -- called PDF Presentation . With an XMP-enabled application like Photoshop CS, information about a objects and properties XAP. 1.10 What's Next The next chapter describes the Photoshop Object Model and shows how it can be used to script
  • Adobe 23101764 | Scripting Guide - Page 12
    Photoshop document as a series of layers and channels - or objects. Automating Photoshop with scripting requires the same object-oriented type of thinking. The heart of a scriptable application is the object model. In Photoshop Photoshop Photoshop. The Photoshop Photoshop Photoshop,
  • Adobe 23101764 | Scripting Guide - Page 13
    doors are subclasses of an openings class, since they are both openings in a house. In Photoshop, art layers, for example, inherit from the layer class. Classes often have properties that of current document Visual Basic appRef.ActiveDocument.LayerSets(1).Layers(1) Photoshop CS Scripting Guide 9
  • Adobe 23101764 | Scripting Guide - Page 14
    the active object you are working with and the gateway to the main components of the Photoshop object model. Document Class The Document class is used to make modifications to the documents. For more information on document objects, see Section 3.9 on page 68. Photoshop CS Scripting Guide 10
  • Adobe 23101764 | Scripting Guide - Page 15
    related to the document mode and are called "component channels. In addition to the component channels, Photoshop lets you to create additional channels. You can create a "spot color channel", a "masked area more information on channels, see Section 3.14 on page 89. Photoshop CS Scripting Guide 11
  • Adobe 23101764 | Scripting Guide - Page 16
    A Text Item is a particular type of art layer that allows you to add type to an image. In Photoshop, a text item is implemented as a property of the art layer. For more information on text items, see Section objects in various formats and to specify color options. Photoshop CS Scripting Guide 12
  • Adobe 23101764 | Scripting Guide - Page 17
    CD Raw Generic PDF Generic EPS Save Classes Save Options Photoshop BMP GIF EPS JPEG PDF Pict Pict File Resource Pixar the SolidColor object handles all colors. The solid color classes available in Photoshop are illustrated below. For more information on colors, see Section 3.15 on
  • Adobe 23101764 | Scripting Guide - Page 18
    end -- writing Photoshop scripts that accomplish something such a message in Photoshop CS using AppleScript, Visual Basic or JavaScript. Regardless of the language employed, the basic steps involved are the same: • Open the Photoshop scripts in Photoshop CS. To see
  • Adobe 23101764 | Scripting Guide - Page 19
    instruct the Photoshop application to create a new document with width and height in inches and place an art layer within the document. The art layer is then changed to a text layer, whose contents are set to "Hello World!". tell application "Adobe Photoshop CS Photoshop CS Scripting Guide 15
  • Adobe 23101764 | Scripting Guide - Page 20
    2 Object Model JavaScript Sample Code This code contains JavaScript commands that instruct Photoshop to remember current unit settings and then create a new document with JavaScript programmers may want to skip to Chapter 3 for specifics on scripting Photoshop. Photoshop CS Scripting Guide 16
  • Adobe 23101764 | Scripting Guide - Page 21
    In some cases, individual script lines are too long to print on a single line in this guide. AppleScript AppleScript uses the special character (¬) to show that the line continues to the next line character, which is a space followed by an underscore ( _). Photoshop CS Scripting Guide 17
  • Adobe 23101764 | Scripting Guide - Page 22
    reference A specific reference to an object. current document record An unordered list of properties, Each property is identified by its label. {name: "you", index: 1} Photoshop CS Scripting Guide 18
  • Adobe 23101764 | Scripting Guide - Page 23
    to nothing. Object Properties and methods belonging to an object or array. Undefined Devoid of any value Example: "Hello" 3.7 true null activeDocument undefined Photoshop CS Scripting Guide 19
  • Adobe 23101764 | Scripting Guide - Page 24
    To put data into a variable, assign the data to the variable. The file name of the current Photoshop document or the current date are both examples of data that can be assigned to a variable. By using variables you use the variable you should not use the var keyword. Photoshop CS Scripting Guide 20
  • Adobe 23101764 | Scripting Guide - Page 25
    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 a number, and they can't contain punctuation or quotation marks. Photoshop CS Scripting Guide 21
  • Adobe 23101764 | Scripting Guide - Page 26
    change object properties. JS In JavaScript, use the add() method to create new objects, and the assignment operator (=) to assign both object references and variables. Photoshop CS Scripting Guide 22
  • Adobe 23101764 | Scripting Guide - Page 27
    no documents are open, the scripts display a messages in a dialog box. AS tell application "Adobe Photoshop CS" set documentCount to count every document if documentCount = 0 then display dialog "No Photoshop documents are open!" end if end tell VB Private Sub Command1_Click() Dim documentCount As
  • Adobe 23101764 | Scripting Guide - Page 28
    " end repeat set flag to false repeat while flag = false set flag to button returned of (display dialog "Later?" ¬ buttons {"Yes", "No"}) = "No" end repeat Photoshop CS Scripting Guide 24
  • Adobe 23101764 | Scripting Guide - Page 29
    's nothing special about the code used in subroutines - they are conveniences that save you from having to retype the same code lines in your script. Photoshop CS Scripting Guide 25
  • Adobe 23101764 | Scripting Guide - Page 30
    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. Photoshop CS Scripting Guide 26
  • Adobe 23101764 | Scripting Guide - Page 31
    and run your script. As the script executes, you'll see the commands sent to Photoshop, and the Photoshop responses. You can display the contents of one or more variables in the log window by AppleScript, see the AppleScript Reference Guide on the installation CD. Photoshop CS Scripting Guide 27
  • Adobe 23101764 | Scripting Guide - Page 32
    > Watch Window." Check your Visual Basic documentation for more information. Windows Scripting Host also provides debugging information. For more information on using Visual Basic with Photoshop, see the VisualBasic Reference Guide on the installation CD. Photoshop CS Scripting Guide 28
  • Adobe 23101764 | Scripting Guide - Page 33
    is described in detail in the JavaScript Reference Guide on the Photoshop installation CD. Please refer to that document for Document" --If it does not exist, display an error message tell application "Adobe Photoshop CS" try set docRef to document "My Document" display dialog "Found 'My Document
  • Adobe 23101764 | Scripting Guide - Page 34
    .description); } 2.11 What's Next The next chapter covers Photoshop-specific objects and components and describes advanced techniques for scripting the Photoshop application. The "Hello, World!" example is entended to include text filtering and document selection. Photoshop CS Scripting Guide 30
  • Adobe 23101764 | Scripting Guide - Page 35
    of all open documents named "MyDocument." tell application "Adobe Photoshop CS" set color profile kind of document "MyDocument" to none end tell 3.2 Viewing Photoshop objects, commands and methods This section shows how to view Photoshop's objects, commands and properties in AppleScript and Visual
  • Adobe 23101764 | Scripting Guide - Page 36
    Photoshop application and click the "Open" button. Script Editor displays a list of Photoshop : When viewing the Photoshop dictionary using Apple's Photoshop DCS 1.0/ Photoshop DCS 2.0/Photoshop EPS/Photoshop format/Photoshop Photoshop DCS 1.0/Photoshop DCS 2.0/ Photoshop EPS/Photoshop PDF/Photoshop
  • Adobe 23101764 | Scripting Guide - Page 37
    2. Turn on the "Adobe Photoshop CS Object Library" option from the Photoshop, however, provides a built-in run-time environment for executing JavaScripts. For more information on using JavaScript with Photoshop, see the JavaScript Reference Guide on the installation CD. Photoshop CS Scripting Guide
  • Adobe 23101764 | Scripting Guide - Page 38
    a JavaScript for execution. JavaScripts display here A collection of JavaScripts comes pre-installed with Photoshop. These scripts display alongside the Scripts menu, as illustrated above. You can use these containing the error message returned by the script. Photoshop CS Scripting Guide 34
  • Adobe 23101764 | Scripting Guide - Page 39
    JavaScripts only. 3.3 Your first Photoshop script The traditional first project in ll create a new Photoshop document, then add change its -- contents. tell application "Adobe Photoshop CS" -- Create a new document and tell 3. Run the script. Photoshop will create a new document, add a new
  • Adobe 23101764 | Scripting Guide - Page 40
    script 3.3.2 Visual Basic 1. Start Visual Basic and create a new project. Add the "Adobe Photoshop CS Object Library" reference to the project, as shown earlier. If you are using a built- (We'll expand on this example in the Advanced Scripting section that follows). Photoshop CS Scripting Guide 36
  • Adobe 23101764 | Scripting Guide - Page 41
    . 7. Return to Visual Basic and run the program. If you created a form, click the button you created earlier. 8. Run the script. Photoshop will create a new document, add a new art layer, change the art layer's type to text and set the text to "Hello, World!" Photoshop CS Scripting Guide 37
  • Adobe 23101764 | Scripting Guide - Page 42
    and everything that comes after the "as" (in this case Photoshop.ArtLayer). - VBScript does not support the "as New Photoshop.Application" form. In Visual Basic you can retrieve the Application be used -- not the term "psTextLayer". For example: artLayerRef.Kind = 2 Photoshop CS Scripting Guide 38
  • Adobe 23101764 | Scripting Guide - Page 43
    in VBScript with comments included. ' Hello World Script Dim appRef Set appRef = CreateObject( "Photoshop.Application" ) ' Remember current unit settings and then set units to ' the value through the script, you'll see how to create, then address, each object. Photoshop CS Scripting Guide 39
  • Adobe 23101764 | Scripting Guide - Page 44
    . var textItemRef = artLayerRef.textItem; textItemRef.contents = "Hello, World!"; // Release references docRef = null; artLayerRef = null; textItemRef = null; // Restore original ruler unit setting app.preferences.rulerUnits = originalUnit; Photoshop CS Scripting Guide 40
  • Adobe 23101764 | Scripting Guide - Page 45
    Scripting Photoshop 3 Advanced Scripting 3.4 Advanced Scripting Having familiarized yourself with the basic " , the first of which deals with configuring document preferences. NOTE: In JavaScript, the Photoshop Application object is already created for you behind the scenes. You do not have to make
  • Adobe 23101764 | Scripting Guide - Page 46
    up using the File/Edit/Preferences dialog when you initially installed and configured Photoshop. The script goes on to define new preferences for rulers and units (docWidthInInches, docHeightInInches, resolution); This code produces the blank document displayed below. Photoshop CS Scripting Guide 42
  • Adobe 23101764 | Scripting Guide - Page 47
    . NOTE: For a complete listing of all JavaScript properties, methods and constants (such as TEXT), please refer to the JavaScript Reference Guide, included as a separate document with Photoshop CS. Next, set the text, position, size and color of the text layer. The content of the text layer is the
  • Adobe 23101764 | Scripting Guide - Page 48
    Scripting Photoshop 3 Advanced Scripting Applying a Wave Filter Now that text displays on your document, you're ready to apply 100, 100, WaveType.SINE, UndefinedAreas.WRAPAROUND, 0); This code snippet manipulates and bends the text on the left side of the document. Photoshop CS Scripting Guide 44
  • Adobe 23101764 | Scripting Guide - Page 49
    Scripting Photoshop 3 Advanced Scripting Applying a MotionBlur Filter Similar code can be used to blur the text in a document. Again = startDisplayDialogs; This code snippet removes the "marching ants" and blurs the text on the right side of the document. Photoshop CS Scripting Guide 45
  • Adobe 23101764 | Scripting Guide - Page 50
    As Photoshop.SolidColor Dim newTextLayer As Photoshop.ArtLayer Dim Preferences As Photoshop.Preferences Set app = New Photoshop.Application startRulerUnits = app.Preferences.RulerUnits startTypeUnits = app.Preferences.TypeUnits startDisplayDialogs = app.DisplayDialogs Photoshop CS Scripting Guide
  • Adobe 23101764 | Scripting Guide - Page 51
    a complete listing of all Visual Basic properties, methods and constants (such as psTextLayer), please refer to the Visual Basic Reference Guide, included as a separate document with Photoshop CS. Next, set the text, position, size and color of the text layer. The content of the text layer is the
  • Adobe 23101764 | Scripting Guide - Page 52
    whose function is to display text in red. Set docRef = app.ActiveDocument Set textColor = New Photoshop.SolidColor textColor.RGB.Red = 255 textColor.RGB.Green = 0 textColor.RGB.Blue = 0 Set the document. "Ants marching up the page" delimit the area selected. Photoshop CS Scripting Guide 48
  • Adobe 23101764 | Scripting Guide - Page 53
    (0, 0)) newTextLayer.ApplyWave 1, 1, 100, 5, 10, 100, 100, _ Photoshop.PsWaveType.psSine, _ Photoshop.PsUndefinedAreas.psWrapAround, 0 This code snippet manipulates and bends the text on the remove the selection so that the "marching ants" disappear from the dialog. Photoshop CS Scripting Guide 49
  • Adobe 23101764 | Scripting Guide - Page 54
    you most probably set up using the File/Edit/Preferences dialog when you initially installed and configured Photoshop. The script goes on to define new preferences for rulers and units and sets these to "OK" each time the script generates a new dialog for display. Photoshop CS Scripting Guide 50
  • Adobe 23101764 | Scripting Guide - Page 55
    document object is created, if one does not already exist. tell application "Adobe Photoshop CS" activate set theStartRulerUnits to ruler units of settings set theStartTypeUnits to type name:theDocString} end if This code produces the blank document displayed below. Photoshop CS Scripting Guide 51
  • Adobe 23101764 | Scripting Guide - Page 56
    For a complete listing of all AppleScript properties, methods and constants (such as text layer), please refer to the AppleScript Reference Guide, included as a separate document with Photoshop CS. Next, set the text, position, size and color of the text layer. The contents of the text layer is the
  • Adobe 23101764 | Scripting Guide - Page 57
    Scripting Photoshop 3 Advanced Scripting Applying a Wave Filter Now that text displays on your document, you're ready to apply maximum amplitude:10 ¬ , horizontal scale:100, vertical scale:100 ¬ , wave type:sine, undefined areas:repeat edge pixels,¬ random seed:0} Photoshop CS Scripting Guide 53
  • Adobe 23101764 | Scripting Guide - Page 58
    Scripting Photoshop 3 Advanced Scripting This code snippet manipulates and bends the text on the left side of the document. of settings to theStartRulerUnits set type units of settings to theStartTypeUnits set display dialogs to theStartDisplayDialogs end tell Photoshop CS Scripting Guide 54
  • Adobe 23101764 | Scripting Guide - Page 59
    possible for document 1 to not be the front-most document. For this reason Photoshop will always return object references identifying documents by name. It is recommended that you the following sample script: 1. tell application "Adobe Photoshop CS" 2. activate Photoshop CS Scripting Guide 55
  • Adobe 23101764 | Scripting Guide - Page 60
    on line five. Try referencing the objects by name as shown below: 1. tell application "Adobe Photoshop CS" 2. activate 3. set newDocument to make new document with properties ¬ { width: inches " 'restore unit values appRef.Preferences.RulerUnits = originalRulerUnits Photoshop CS Scripting Guide 56
  • Adobe 23101764 | Scripting Guide - Page 61
    Photoshop objects and properties note where unit values are used. Because of scripting language differences, the way you provide a unit value in a script depends on the language you are using. All languages support you should check and set the ruler units to the type Photoshop CS Scripting Guide 57
  • Adobe 23101764 | Scripting Guide - Page 62
    points This would return a value of 360 (5 inches x 72 points per inch). IMPORTANT: Because Photoshop is a pixel-oriented application you may not always get back the same value as you pass in ciceros millimeters centimeters meters kilometers picas traditional picas Photoshop CS Scripting Guide 58
  • Adobe 23101764 | Scripting Guide - Page 63
    * someValue Special unit value types The unit values used by Photoshop are length units, representing values of linear measurement. Support is also included for pixel and percent unit values. These two a coercion error when run set inchValue to pixelValue as inches Photoshop CS Scripting Guide 59
  • Adobe 23101764 | Scripting Guide - Page 64
    width BaselineShift* FirstLineIndent* Height HyphenationZone* Leading* LeftIndent* Position RightIndent* SpaceBefore* SpaceAfter* Width baselineShift* firstLineIndent* height hyphenationZone* leading* leftIndent* position rightIndent* spaceBefore* spaceAfter* width Photoshop CS Scripting Guide 60
  • Adobe 23101764 | Scripting Guide - Page 65
    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. Be sure to set the ruler units as pixel units set point size of settings to postscript size Photoshop CS Scripting Guide 61
  • Adobe 23101764 | Scripting Guide - Page 66
    contains the JavaScript code as illustrated below: AS: set scriptFile to "myscript" as alias do javascript scriptFile VB: Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application") appRef.DoJavaScriptFile ("D:\\Scripts\\MosaicTiles.js") Photoshop CS Scripting Guide 62
  • Adobe 23101764 | Scripting Guide - Page 67
    [i].toString() ) } To pass arguments from AppleScript try this: tell application "Adobe Photoshop CS" make new document do javascript (alias
  • Adobe 23101764 | Scripting Guide - Page 68
    tell block. By enclosing your Photoshop commands in the following statement, AppleScript will understand you are targeting Photoshop. tell application "Adobe Photoshop CS" ... end tell In Visual (ActiveDocument/activeDocument)" property on the application object. Photoshop CS Scripting Guide 64
  • Adobe 23101764 | Scripting Guide - Page 69
    or not dialogs are displayed. If you set display dialogs to always ( psDisplayAllDialogs/ALL ), Photoshop will show all user related dialogs. This is typically not what you want. If you set .4, "Error handling" on page 29 for more information on catching errors. Photoshop CS Scripting Guide 65
  • Adobe 23101764 | Scripting Guide - Page 70
    values needed in your script. Specifying file formats to open Because Photoshop supports many different file formats, the Open command lets you specify the format (PhotoCDOpenOptions/PhotoCDOpenOptions) • raw format Options (RawFormatOpenOptions/RawFormatOpenOptions) Photoshop CS Scripting Guide 66
  • Adobe 23101764 | Scripting Guide - Page 71
    object The following example shows how to open a generic PDF document. AS: tell application "Adobe Photoshop CS" set myFilePath to alias < a file path > open myFilePath as PDF with options = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; Photoshop CS Scripting Guide 67
  • Adobe 23101764 | Scripting Guide - Page 72
    paste within the active document or between different documents. 3.9.1 Saving documents and save options Photoshop lets you work with various file formats. It is important to note, however, that the • Alias PIX • Electric Image • SGI RGB • Wavefront RLA • SoftImage Photoshop CS Scripting Guide 68
  • Adobe 23101764 | Scripting Guide - Page 73
    JPEG save options (JPEGSaveOptions/JPEGSaveOptions) class as shown below. AS: tell application "Adobe Photoshop CS" make new document set myOptions to {class:JPEG save options, ¬ embed color Options:=jpgSaveOptions, _ asCopy:=True, extensionType:=psLowercase Photoshop CS Scripting Guide 69
  • Adobe 23101764 | Scripting Guide - Page 74
    www.adobe.com" VB: Set docInfoRef = docRef.Info docInfoRef.Copyrighted = psCopyrightedWork docInfoRef.OwnerUrl = "http://www.adobe.com" JS: docInfoRef = docRef.info; docInfoRef.copyrighted = CopyrightedType.COPYRIGHTEDWORK; docInfoRef.ownerUrl = "http://www.adobe.com"; Photoshop CS Scripting Guide
  • Adobe 23101764 | Scripting Guide - Page 75
    Scripting Photoshop 3 Document object 3.9.3 Document manipulation The Document object is used to make modifications to the document image. By using the 72 width 20 height 20 VB: docRef.Crop Array(10,20,40,50), Angle:=45, Width:=20, _ Height:=20, Resolution:=72 Photoshop CS Scripting Guide 71
  • Adobe 23101764 | Scripting Guide - Page 76
    psHorizontal JS: docRef.flipCanvas(Direction.HORIZONTAL); 3.10 Layer objects Photoshop has 2 types of layers: an art layer that can contain red at the beginning of the current document AS: tell application "Adobe Photoshop CS" make new art layer at beginning of current document ¬ with properties
  • Adobe 23101764 | Scripting Guide - Page 77
    a color to be used with the fill command Dim colorObj As Photoshop.SolidColor Set colorObj = CreateObject("Photoshop.SolidColor") colorObj.RGB.Red = 255 colorObj.RGB.Green = 100 Now apply fill to the current selection app.activeDocument.selection.fill(colorRef); Photoshop CS Scripting Guide 73
  • Adobe 23101764 | Scripting Guide - Page 78
    : AS: tell application "Adobe Photoshop CS" make new layer set after layer 1 of current document end tell VB: Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application") ' Get a When you do this the text in the layer is rasterized. Photoshop CS Scripting Guide 74
  • Adobe 23101764 | Scripting Guide - Page 79
    Scripting Photoshop 3 Layer objects 3.10.1 Setting the Active layer Before attempting to manipulate a layer you must first select it. You can to make new layer set at end of current document duplicate layer "Layer 1" of current document to end of layerSetRef Photoshop CS Scripting Guide 75
  • Adobe 23101764 | Scripting Guide - Page 80
    ElementPlacement.PLACEATEND); layerRef.moveToEnd (layerSetRef); 3.10.3 Linking layers Scripting also supports linking and unlinking layers. You may want to link layers together so .artLayers.add(); var layerRef2 = docRef.artLayers.add(); layerRef1.link(layerRef2); Photoshop CS Scripting Guide 76
  • Adobe 23101764 | Scripting Guide - Page 81
    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 -language format used above. See "Conventions in this guide" on page 1. Photoshop CS Scripting Guide 77
  • Adobe 23101764 | Scripting Guide - Page 82
    Scripting Photoshop 3 Text item object By changing an art layer's kind, you can also convert an existing layer to text as long as of text object of art layer "my text" of ¬ current document to right VB: docRef.ArtLayers("my text").TextItem.Justification = psRight Photoshop CS Scripting Guide 78
  • Adobe 23101764 | Scripting Guide - Page 83
    Scripting Photoshop 3 Text item object JS: docRef.artLayers["my text"].textItem.justification = Justification.RIGHT; IMPORTANT: The text item in VB and JS, write the following: VB: textLayerRef.TextItem.Contents = "Hello" JS: textLayerRef.textItem.contents = "Hello"; Photoshop CS Scripting Guide 79
  • Adobe 23101764 | Scripting Guide - Page 84
    PostScript font name. 1. Using the Photoshop user interface, create a new Photoshop document. 2. Create a new text layer and add some text to it. 3. Select the text you created in step 2. 4. Select the desired font from the Font pull down menu (for example, "Arial") Photoshop CS Scripting Guide 80
  • Adobe 23101764 | Scripting Guide - Page 85
    Scripting Photoshop 3 Selections 5. Create a script to get the font name of the text. An example JavaScript is below: var textLayer = activeDocument. for a non-existent selection. When creating new selections, you can add to, replace, or subtract from a selection. Photoshop CS Scripting Guide 81
  • Adobe 23101764 | Scripting Guide - Page 86
    Scripting Photoshop 3 Selections For example, you may apply effects to a selection or copy the current selection to the to replace the current selection: AS: select current document region {{ 5, 5}, {5, 100}, ¬ { 80, 100}, { 80, 5}} combination type replaced Photoshop CS Scripting Guide 82
  • Adobe 23101764 | Scripting Guide - Page 87
    .Preferences.RulerUnits = psPixels 'get selection and replace it Dim docRef As Photoshop.Document Set docRef = appRef.ActiveDocument docRef.Selection.Select Array(Array(50, .REPLACE); // restore unit setting app.preferences.rulerUnits = originalRulerUnits; Photoshop CS Scripting Guide 83
  • Adobe 23101764 | Scripting Guide - Page 88
    of the selection. The values are passed in ruler units, the values of which are stored in Photoshop preferences and can be changed by your scripts. Feathering a selection will smooth its corners by the units" on page 61 for examples of how to change ruler units. Photoshop CS Scripting Guide 84
  • Adobe 23101764 | Scripting Guide - Page 89
    .preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var selRef = app.activeDocument.selection selRef.expand( 5 ); selRef.contract( 5 ); selRef.feather( 5 ); // restore unit setting app.preferences.rulerUnits = originalRulerUnits; Photoshop CS Scripting Guide 85
  • Adobe 23101764 | Scripting Guide - Page 90
    blend mode ¬ vivid light opacity 25 without preserving transparency VB: Set fillColor = CreateObject("Photoshop.SolidColor") fillColor.RGB.Red = 255 fillColor.RGB.Green = 0 fillColor.RGB.Blue = .HistoryStates(10) JS: selRef.fill(app.activeDocument.historyStates[9]); Photoshop CS Scripting Guide 86
  • Adobe 23101764 | Scripting Guide - Page 91
    app.activeDocument.selection.rotateBoundary(45); 3.12.7 Loading and storing selections Photoshop exposes the functionality to store and load selections. Selections get stored psExtendSelection JS: selRef.store(docRef.channels["My Channel"], SelectionType.EXTEND); Photoshop CS Scripting Guide 87
  • Adobe 23101764 | Scripting Guide - Page 92
    Scripting Photoshop 3 Working with Filters To restore a selection that has been saved to a selection, use the load (Load/load) method "Blue." AS: set current channels of current document to { channel "Red" of ¬ current document, channel "Blue" of current document } Photoshop CS Scripting Guide 88
  • Adobe 23101764 | Scripting Guide - Page 93
    Scripting Photoshop 3 Channel object you access to much of the available functionality on Photoshop channels. You can create, delete and duplicate channels or . 3.14.1 Channel types In addition to the component channels, Photoshop lets you to create additional channels. You can create a "spot
  • Adobe 23101764 | Scripting Guide - Page 94
    Scripting Photoshop 3 Channel object If you have an RGB document you automatically get a red, blue and types are: • masked area channel (psMaskedAreaAlphaChannel, ChannelType.MASKEDAREA) • selected area channel (psSelectedAreaAlphaChannel, ChannelType. SELECTEDAREA) Photoshop CS Scripting Guide 90
  • Adobe 23101764 | Scripting Guide - Page 95
    model by assigning the color model values and then set the foreground color to the solid color. Here's how: VB: solidColor = CreateObject("Photoshop.SolidColor") appRef.ForegroundColor = solidColor JS: var solidColor = new SolidColor(); foregroundColor = solidColor; Photoshop CS Scripting Guide 91
  • Adobe 23101764 | Scripting Guide - Page 96
    SolidColor object and set its CMYK property. VB: Dim solidColor As Photoshop.SolidColor Set solidColor = CreateObject("Photoshop.SolidColor") solidColor. CMYK.Cyan = 20 solidColor.CMYK.Magenta = 90 the RGBColor object has a string property called HexValue/hexValue. Photoshop CS Scripting Guide 92
  • Adobe 23101764 | Scripting Guide - Page 97
    Scripting Photoshop 3 also ask the SolidColor object to convert its color to any of the supported models. For example, writing: someColor.cmyk will return a CMYKColor object ' Get the foreground color as Lab Dim myLabColor As Photoshop.LabColor Set myLabColor = appRef.ForegroundColor.Lab JS: // Get
  • Adobe 23101764 | Scripting Guide - Page 98
    web safe color for foreground color VB: Dim myWebSafeColor As Photoshop.RGBColor Set myWebSafeColor = appRef.ForegroundColor.NearestWebColor JS: var webSafeColor .ActiveHistoryState = docRef.HistoryStates(1) JS: docRef.activeHistoryState = docRef.historyStates[0]; Photoshop CS Scripting Guide 94
  • Adobe 23101764 | Scripting Guide - Page 99
    Scripting Photoshop 3 History object The code above sets the current history state to the top history state that is in the History state can also be used to fill a selection. See section 3.12, "Selections" on page 81 for more information on working with selections. Photoshop CS Scripting Guide 95
  • Adobe 23101764 | Scripting Guide - Page 100
    operate on a single document, or to move information between documents. NOTE: On Mac OS, Photoshop must be the front-most application when executing these commands. You must activate the application before : docRef.Selection.Copy True JS: docRef.selection.copy(true); Photoshop CS Scripting Guide 96
  • Adobe 23101764 | Scripting Guide - Page 101
    Scripting Photoshop 3 Clipboard interaction 3.17.3 Cut The Cut command operates on both art layers and selections, so .ActiveDocument = appRef.Documents("Doc2") Set newLayerRef = docRef.Paste JS: activeDocument = documents["Doc2"]; var newLayerRef = docRef.paste(); Photoshop CS Scripting Guide 97
  • Adobe 23101764 | Scripting Guide - Page 102
    Scripting Photoshop 3 Clipboard interaction 3.17.5 Paste into command The paste into command allows you to paste the contents of the newLayerRef to paste with clipping to selection VB: Set newLayerRef = docRef.Paste (True) JS: newLayerRef = docRef.paste( true ); Photoshop CS Scripting Guide 98
  • Adobe 23101764 | Scripting Guide - Page 103
    getting and converting color 93 Hex values 92 Setting a Color 91 web safe colors 94 COM 5 Command and methods JavaScript 22 Photoshop CS Scripting Guide Commands and methods 22 AppleScript 22 Visual Basic 22 Comments in scripts 17 AppleScript 17 JavaScript 17 Visual Basic 17 Conditional statements
  • Adobe 23101764 | Scripting Guide - Page 104
    layers 77 setting the active layer 75 Layer sets 75 Line continuation characters 17 List 18 List value type 18 Long 19 Photoshop CS Scripting Guide N Number 18, 19 Numeric value types 18, 19 O Object classes 8 Object elements or collections 9 Object inheritance 9 Object Model 8 Channel class 11
  • Adobe 23101764 | Scripting Guide - Page 105
    AppleScript dictionary 32 Viewing Photoshop ojects, commands and methods Visual Basic type library 33 Visual Basic advanced 46 Object Browser 33 Visual Basic Values 19 W Warping text 81 Web Photo Gallery 6 Web Safe Color 94 Windows Scripting Host 4 X XMP metadata 7 Photoshop CS Scripting Guide 101
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

ADOBE SYSTEMS INCORPORATED
Corporate Headquarters
345 Park Avenue
San Jose, CA 95110-2704
(408) 536-6000
b
c
October 2003
Photoshop CS
Scripting Guide