These JavaScripts are used to automate tasks within the Adobe Creative Suite. Examples of what you can do with JavaScript and Adobe applications include: exporting multiple layers as individual files within PhotoShop, applying text or image watermarks to PDFs in Acrobat, and replacing placeholder text with images in InDesign.
Getting Started
So how to get started with Adobe scripting? Start by reading the Introduction to Scripting Guide. Then if you are using a CS2 application, download the scripting reference PDF for that application. If you are using CS3 then you can use the built in Object Model in the ExtendScript Toolkit by clicking on “help” and then “Object Model”.
The Introduction to Scripting Guide as well as Adobe scripting references can be found on the Adobe developer connection page. For a list of core JavaScript operaters, check out my JavaScript Operaters page.
Why JavaScript?
When scripting Adobe applications you can choose between three scripting lanuages. AppleScript, JavaScript, and VBScript. JavaScript is the only one of the three that can create cross-platform scripts and has great support on the Adobe user-to-user scripting forums. What JavaScript can’t do though are things such as accessing other non-Adobe programs on your machine such as MS Word. It does however have the ability to invoke other scripts written in different languages to do that. So you could run a JavaScript from your Adobe application and that script could call out to an AppleScript or VBScript if you need to access other programs outside of the creative suite.
Scripts and Actions
So why not just use a macro or an action? Macros/actions are great for automating tasks when all you need is a recording of your interactions with the user interface that you can just replay over and over. Scripting can do this as well, but what it really offers is the ability to add logic in the form of operations, control sequences, and variables. Scripting also has an avantage of being able to work on mulitple files and launch other programs when needed. Such as resizing images in PhotoShop and then sending them to InDesign to be placed into a document. One last note about actions and scripts is that a script can run an action, and an action can run a script. So an easy way to run a script in Photoshop with the push of a button is to create an action that runs a script and assign a keyboard shortcut to that action.
The ExtendScript Toolkit
When you are wrting your JavaScripts any text editor will do. Just be sure to save the file with a .jsx extension. If you are using a version previous to CS2 you'll want to use a .js file extension. Now, while you can write your script in any text editor, using the ExtendScript toolkit to write your scripts has some great advantages. First it colors the code to make it easier to read. It adds line numbers, and starting with CS3 it allows you to collapse and expand sections within your script. It can run your script and assist in debugging. Most importantly though, the ExtendScript toolkit shows all the objects avaliable to your script for the selected application. Examples of objects are: an open document in Acrobat, a layer in Photoshop, or a link in InDesign. A copy of the ExtendScript toolkit comes with all the CS applications. Previous to CS3 Adobe released very large PDFs for each application that contained all the objects with their names, properties and methods for reference when writing scripts. Now the ExtendScript toolkit is the best place to find this information. The introduction to scripting PDF includes a tutorial on using the toolkit for looking up objects and finding their properties/methods.
Installing a Script
Once you’ve written a script installing it is a breeze. Just place it in the scripts folder for the application you want to run it in. Such as: C:\Program Files\Adobe\Adobe InDesign CS2\Presets\Scripts. Acrobat is a bit different though, because it can use three different types of scripts: document, folder, and batch. Batch scripts can be installed by adding a batch processing sequence under the advanced tab, and then adding “Execute JavaScript” command to that sequence.
Now that you’ve got the basic idea of scripting Adobe applications, choose one of the tutorials from the right collumn. Each tutorial breaks the script down and explains what each section is for. It also contains the complete script for your own use. The scripts on this site are saved as text files, so just copy the text and paste it into a new document in your ExtendScript Toolkit. Or download the file and change the file extension to .jsx.