You are previewing Adobe® Photoshop® CS2 Official JavaScript Reference.
O'Reilly logo
Adobe® Photoshop® CS2 Official JavaScript Reference

Book Description

Do you spend too much time doing repetitive production tasks such as placing and replacing images, resizing them, dragging them from one document to another, and preparing images for printing instead of being creative? Do you use Adobe Photoshop CS2 and have some experience with scripting? You're in luck. Since Adobe Creative Suite 2 was created with built-in support for scripting, virtually every repetitive or time-consuming task that creative professionals have to do in the Adobe Creative Suite can be streamlined with the help of a script. This book describes how to use JavaScript to manipulate and extend Adobe Photoshop within Adobe Creative Suite 2, and provides reference information for the JavaScript objects, properties, and functions defined by Adobe's applications. Now available in print for the first time, this scripting reference provides the information experienced JavaScript users need to create custom scripts for Photoshop, whether you're looking to automate Camera Raw options and settings, automatically resize and export large batches of images into your page-layout application, or want to automatically add metadata, like a copyright notice, to selected image files. These are just a few examples of how you can use Photoshop CS2's built-in scripting capabilities to save you from hours of repetitive tasks.

Table of Contents

  1. Copyright
  2. 1. Introduction
    1. Advisory of previous publication
    2. What’s in this book
    3. Running JavaScript
    4. New features
  3. 1. Photoshop Scripting Guide
    1. 2. Scripting Basics
      1. What is scripting?
      2. Why use scripting?
      3. Why use scripts instead of actions?
      4. Introducing objects
      5. Writing script statements
        1. Syntax
      6. Object model concepts
        1. Containment hierarchy
        2. Applying the concept to Adobe Photoshop CS2
      7. Adobe Photoshop CS2’s Object Model
      8. Object collections
        1. Indexes or Indices
        2. Referring to an object in a collection
      9. Object references
      10. Using methods
        1. Methods and arguments
      11. Using variables
        1. Why use variables?
        2. Data contained in variables
        3. Creating variables and assigning values
          1. JavaScript value types
        4. Naming variables
      12. Using object properties
        1. Understanding and finding constants
      13. Understanding object classes and inheritance
      14. Using arrays
      15. Documenting scripts
        1. Comment syntax
      16. Creating a sample Hello World script
        1. Creating and running a JavaScript
        2. What’s next
      17. Using operators
        1. Comparison operators
      18. Using conditional statements
        1. Loops
          1. Simple loops
          2. More complex loops
      19. Using subroutines, handlers, and functions
      20. Troubleshooting and error handling
      21. Bibliography
    2. 3. Scripting Adobe Photoshop CS2
      1. Viewing Photoshop CS2 objects, commands, and methods
      2. Creating new objects in a script
      3. Setting the active object
        1. Setting the active document
        2. Setting the active layer
        3. Setting the active channels
      4. Opening a document
        1. Specifying file formats to open
      5. Saving a document
      6. Setting application preferences
      7. Suppressing dialog boxes
      8. Working with the Adobe Photoshop CS2 Object Model
        1. Using the Application object
        2. Using the Document object
          1. Manipulating a Document object
        3. Working with layer objects
        4. Creating an ArtLayer object
          1. Referencing ArtLayer objects
        5. Working with layer set objects
          1. Linking Layer Objects
          2. Applying styles to layers
        6. Using the Text Item object
          1. Creating a Text Item object
            1. Determining a layer’s kind
            2. Adding and manipulating text in a text item object
        7. Working with Selection objects
          1. Creating and defining a selection
          2. Stroking the selection border
          3. Inverting selections
          4. Expanding, contracting, and feathering selections
          5. Filling a selection
          6. Loading and storing selections
        8. Working with Channel objects
          1. Changing channel types
        9. Using the DocumentInfo object
        10. Using history state objects
        11. Using Notifier objects
        12. Using the PathItem object
      9. Working with color objects
        1. Solid color classes
        2. Using hex values
        3. Getting and converting colors
          1. Comparing colors
          2. Getting a web safe color
      10. Working with filters
        1. Other filters
      11. Understanding clipboard interaction
        1. Using the Copy and Paste methods
        2. Using the Copy Merged method
      12. Working with units
        1. Unit values
          1. Special unit value types
          2. Using unit values in calculations
        2. Unit value usage
        3. Setting ruler and type units in a script
      13. Sample workflow automation JavaScripts
      14. Advanced scripting
        1. Working with document preferences
        2. Applying color to a text item
        3. Applying a wave filter
          1. Defining the area of a selection object
        4. Applying a motionblur filter
  4. 2. Photoshop JavaScript Reference
    1. 4. Using JavaScript with Adobe Photoshop CS2
      1. Script Support in Adobe Photoshop CS2
        1. JavaScript support
        2. Executing scripts
          1. Installing scripts
          2. Executing other scripts
        3. Startup scripts
      2. Changes since earlier versions
        1. Changes in ScriptUI
    2. 5. JavaScript Object Reference
      1. Working with the Properties tables
      2. Working with the Methods tables
        1. Working with method parameters
      3. ActionDescriptor
        1. Properties
        2. Methods
      4. ActionList
        1. Methods
      5. ActionReference
        1. Properties
        2. Methods
      6. Application
        1. Properties
        2. Methods
          1. First Sample Script
            1. Application.jsx
          2. Second Sample Script
            1. PDFPresentation.jsx
      7. ArtLayer
        1. Properties
        2. Methods
          1. Sample Script
            1. ArtLayer.jsx
      8. ArtLayers
        1. Properties
        2. Methods
      9. BatchOptions
        1. Properties
      10. BitmapConversionOptions
        1. Properties
      11. BMPSaveOptions
        1. Properties
      12. CameraRawOpenOptions
        1. Properties
      13. Channel
        1. Properties
        2. Methods
      14. Channels
        1. Properties
        2. Methods
          1. Sample Script
            1. Histogram.jsx
      15. CMYKColor
        1. Properties
      16. ContactSheetOptions
        1. Properties
      17. DCS1_SaveOptions
        1. Properties
      18. DCS2_SaveOptions
        1. Properties
      19. Document
        1. Properties
        2. Methods
          1. Sample Script
            1. Document.jsx
      20. DocumentInfo
        1. Properties
          1. Sample Script
            1. DocumentInfo.jsx
      21. Documents
        1. Properties
        2. Methods
      22. EPSOpenOptions
        1. Properties
      23. EPSSaveOptions
        1. Properties
      24. ExportOptionsIllustrator
        1. Properties
      25. ExportOptionsSaveForWeb
        1. Properties
      26. GalleryBannerOptions
        1. Properties
      27. GalleryCustomColorOptions
        1. Properties
      28. GalleryImagesOptions
        1. Properties
      29. GalleryOptions
        1. Properties
      30. GallerySecurityOptions
        1. Properties
      31. GalleryThumbnailOptions
        1. Properties
      32. GIFSaveOptions
        1. Properties
      33. GrayColor
        1. Properties
      34. HistoryState
        1. Properties
      35. HistoryStates
        1. Properties
        2. Methods
      36. HSBColor
        1. Properties
      37. IndexedConversionOptions
        1. Properties
      38. JPEGSaveOptions
        1. Properties
      39. LabColor
        1. Properties
      40. LayerComp
        1. Properties
        2. Methods
      41. LayerComps
        1. Properties
        2. Methods
      42. Layers
        1. Properties
        2. Methods
      43. LayerSet
        1. Properties
        2. Methods
      44. LayerSets
        1. Properties
        2. Methods
          1. Sample Script
            1. LayerSets.jsx
      45. LensBlurOptions
        1. Properties
      46. NoColor
        1. Properties
      47. Notifier
        1. Properties
        2. Methods
      48. Notifiers
        1. Properties
        2. Methods
      49. PathItem
        1. Properties
        2. Methods
          1. Sample Script
            1. Paths.jsx
      50. PathItems
        1. Properties
        2. Methods
      51. PathPoint
        1. Properties
      52. PathPointInfo
        1. Properties
      53. PathPoints
        1. Properties
      54. PDFOpenOptions
        1. Properties
      55. PDFSaveOptions
        1. Properties
      56. PhotoCDOpenOptions
        1. Properties
      57. PhotoshopSaveOptions
        1. Properties
      58. PICTFileSaveOptions
        1. Properties
      59. PICTResourceSaveOptions
        1. Properties
      60. PicturePackageOptions
        1. Properties
      61. PixarSaveOptions
        1. Properties
      62. PNGSaveOptions
        1. Properties
      63. Preferences
        1. Properties
      64. PresentationOptions
        1. Properties
      65. RawFormatOpenOptions
        1. Properties
      66. RawSaveOptions
        1. Properties
      67. RGBColor
        1. Properties
      68. Selection
        1. Properties
        2. Methods
          1. Sample Script
            1. Selection.jsx
      69. SGIRGBSaveOptions
        1. Properties
      70. SolidColor
        1. Properties
        2. Methods
      71. SubPathInfo
        1. Properties
      72. SubPathItem
        1. Properties
      73. SubPathItems
        1. Properties
        2. Methods
      74. TargaSaveOptions
        1. Properties
      75. TextFont
        1. Properties
      76. TextFonts
        1. Properties
        2. Methods
      77. TextItem
        1. Properties
        2. Methods
      78. TiffSaveOptions
        1. Properties
      79. xmpMetadata
        1. Properties
    3. 6. Action Manager
      1. The ScriptListener plug-in
        1. Installing ScriptListener
      2. Action Manager scripting objects
      3. Using the Action Manager from JavaScript
    4. 7. Using ScriptUI
      1. Overview
      2. ScriptUI Programming Model
        1. Creating a window
        2. Container elements
        3. Window layout
        4. Adding elements to containers
          1. Creation properties
          2. Accessing child elements
        5. Removing elements
        6. Types of controls
          1. Containers
          2. User interface controls
        7. Displaying icons
        8. Prompts and alerts
        9. Modal dialogs
          1. Creating and using modal dialogs
          2. Dismissing a modal dialog
          3. Default and cancel elements
      3. Resource specifications
      4. Defining behavior for controls with event callbacks
        1. Defining event handler functions
        2. Simulating user events
      5. Automatic layout
        1. Default layout behavior
        2. Automatic layout properties
          1. Container orientation
          2. Aligning children
          3. Setting margins
          4. Spacing between children
          5. Determining a preferred size
          6. Creating more complex arrangements
          7. Creating dynamic content
        3. Custom layout manager example
        4. The AutoLayoutManager algorithm
        5. Automatic layout restrictions
      6. Example scripts
        1. Alert box builder
          1. Resource specification example
      7. Localization in ScriptUI objects
        1. Variable values in localized strings
        2. Enabling automatic localization
    5. 8. ScriptUI Object Reference
      1. Overview
      2. Window Class
        1. Window class properties
        2. Window class functions
      3. Window object
        1. Window object constructor
        2. Window object properties
        3. Container properties
        4. Window object functions
        5. Window event-handling callbacks
      4. Control objects
        1. Control object constructors
          1. Control types and creation parameters
        2. Control object properties
        3. Control object functions
        4. Control event-handling callbacks
      5. Size and Location Objects
      6. LayoutManager object
        1. AutoLayoutManager object constructor
        2. AutoLayoutManager object properties
        3. AutoLayoutManager object functions
      7. MenuElement Object
        1. MenuElement class functions
          1. Creating new menu elements
        2. MenuElement object properties
        3. Bridge menu and command identifiers
          1. Bridge menu identifiers
          2. Bridge submenu and command identifiers
            1. Bridge menu commands (Mac OS only)
            2. File menu commands
            3. Edit menu commands
            4. Tools menu commands
            5. Label menu commands
            6. View menu commands
            7. Window menu commands
            8. Help menu commands
            9. Context menu commands
    6. 9. Using File and Folder Objects
      1. Overview
      2. Specifying paths
        1. Absolute and relative path names
        2. Character interpretation in paths
        3. The home directory
        4. Volume and drive names
          1. Mac OS volumes
          2. Windows drives
        5. Aliases
        6. Portability issues
      3. Unicode I/O
      4. File Error Handling
    7. 10. File and Folder Object Reference
      1. Overview
      2. File object
        1. File object constructors
        2. File class properties
        3. File class functions
        4. File object properties
        5. File object functions
      3. Folder Object
        1. Folder object constructors
        2. Folder class properties
        3. Folder class functions
        4. Folder object properties
        5. Folder object functions
      4. File and Folder Error Messages
      5. File and Folder Supported Encoding Names
        1. Additional encodings
          1. Common encoding names
          2. Additional Windows encoding names
          3. Additional Mac OS encoding names
          4. UNIX encodings
    8. 11. Scripting Constants
    9. 12. ExtendScript Tools and Features
      1. The ExtendScript Toolkit
        1. Configuring the Toolkit window
        2. Selecting a debugging target
        3. Selecting scripts
        4. Tracking data
        5. The JavaScript console
        6. The call stack
        7. The Script Editor
          1. Mouse navigation and selection
          2. Keyboard navigation and selection
          3. Syntax checking
        8. Debugging in the Toolkit
          1. Evaluation in help tips
          2. Controlling code execution
          3. Visual indication of execution states
          4. Setting breakpoints
            1. Breakpoint icons
            2. The Breakpoints tab
        9. Profiling
      2. Dollar ($) Object
        1. Dollar ($) object properties
        2. Dollar ($) object functions
          1. Object statistics
      3. ExtendScript Reflection Interface
        1. Reflection Object
          1. Reflection object properties
          2. Reflection object functions
        2. ReflectionInfo Object
          1. ReflectionInfo object properties
      4. Localizing ExtendScript Strings
        1. Variable values in localized strings
        2. Enabling automatic localization
        3. Locale names
        4. Testing localization
        5. Global localize function
      5. User Notification Helper Functions
        1. Global alert function
        2. Global confirm function
        3. Global prompt function
      6. Specifying Measurement Values
        1. UnitValue Object
          1. UnitValue object constructor
          2. UnitValue object properties
          3. UnitValue object functions
        2. Converting pixel and percentage values
        3. Computing with unit values
      7. Modular Programming Support
        1. Preprocessor directives
        2. Importing and exporting between scripts
      8. Operator Overloading
      9. Application and Namespace Specifiers
        1. Application specifiers
        2. Namespace specifiers
      10. Script Locations and Checking Application Installation
    10. A. Event ID Codes