iii
Contents
1 Introduction ................................................................................................................................. 1
About this manual.......................................................................................................................................................................... 1
What is scripting? ........................................................................................................................................................................... 2
Why use scripting?......................................................................................................................................................................... 2
Why use scripts instead of Actions?......................................................................................................................................... 2
System requirements.................................................................................................................................................................... 3
Choosing a scripting language ................................................................................................................................................. 4
New Features ................................................................................................................................................................................... 5
2 Scripting basics ............................................................................................................................ 6
Introducing Objects....................................................................................................................................................................... 6
Writing Script Statements ........................................................................................................................................................... 7
Object Model Concepts ............................................................................................................................................................... 7
Photoshop CS2’s Object Model................................................................................................................................................. 8
Object Elements and Collections.............................................................................................................................................. 9
Object References ........................................................................................................................................................................11
Using Commands and Methods .............................................................................................................................................12
Using Variables..............................................................................................................................................................................13
Using Object Properties.............................................................................................................................................................18
Understanding Object Classes and Inheritance................................................................................................................19
Using Arrays ...................................................................................................................................................................................19
Documenting Scripts ..................................................................................................................................................................20
Using Long Script Lines..............................................................................................................................................................21
Creating a Sample Hello World Script...................................................................................................................................21
Using Operators............................................................................................................................................................................25
Using Conditional Statements.................................................................................................................................................26
Using Subroutines, Handlers and Functions......................................................................................................................29
Executing JavaScripts from AS or VBS ..................................................................................................................................31
Passing AS or VBS Arguments to JavaScript.......................................................................................................................31
Testing and Troubleshooting ..................................................................................................................................................32
Bibliography...................................................................................................................................................................................34
3 Scripting Photoshop CS2 .......................................................................................................... 36
Viewing Photoshop CS2 Objects, Commands and Methods .......................................................................................36
Targeting and Referencing the Application Object.........................................................................................................37
Creating New Objects in a Script............................................................................................................................................37
Setting the Active Object ..........................................................................................................................................................39
Opening a Document .................................................................................................................................................................42
Saving a Document .....................................................................................................................................................................44
Setting Application Preferences ............................................................................................................................................46
Allowing or Preventing Dialogs ..............................................................................................................................................46
Working with the Photoshop CS2 Object Model..............................................................................................................47
Working with Color Objects .....................................................................................................................................................63
Working with Filters ....................................................................................................................................................................65
Understanding Clipboard Interaction ..................................................................................................................................66
Working with Units ......................................................................................................................................................................68