Adobe Photoshop Scripting
by mlk, on a hot summer month of 2004

You’ve probably wanted at one time or another to combine the power of Photoshop’s tools to those of programming scripts. Adobe has made this possible for you with the ‘Scripting Plug-in’, a nifty plug-in that allows users to write little scripts (in Javascript, VBScript or AppleScript) that will take over Photoshop and do what you couldn’t with you mouse and keyboard…

This tool is also aimed at designers which wish to increase the workflow speed (you'll see example scripts by the end of the tutorial which allow you to save all your current images, or save each layer to a separate file etc...). Even though we do use a scripting language, it is not hardcore programming and designers which hate programming should not be scared of this, the step by step tutorial will help you create your first simple scripts and you will later be able to move on to more advanced scripts.

I personally came across scripting when I was given a school yearbook to do; I had text files containing each student's info, his picture and Photoshop. I searched for a way to automate the whole process, and came across the Scripting Plug-in; and the yearbook was done in almost no time !

[An excerpt from the yearbook, done by the scripting plug-in]

Photoshop scripting is much more than what actions and batching can do; for example you can use the ‘if…then’ commands which already multiplies possibilities… Imagine you have a text database, hundreds of pictures, and want to dynamically create business cards – seems tough ? Scripting will do it. It is a unique and excellent tool to automate your needs and save you time, or create something that a human and a mouse would take ages to do.

This tutorial will, through a series of projects, demonstrate some of the capabilities of scripting. This tutorial is aimed at intermediate/advanced users who use Photoshop extensively. I assume you know about batching & actions, and most of Photoshop already. The tutorial is set this way: a) example of what we will create. b) full code c)code explanation... So don't worry if at first you only see a bunch of scripted lines.

All you'll need for that tutorial is a text file editor, Photoshop and to install the
plug-in (it's already bundled with PS CS but you’ll need to download it if you own Photoshop 7 - instructions below).

I have broken this tutorial into many sections, start from the beginning if you have never met scripting.

  1. Preliminary steps
  2. Documents and Layers
  3. Using Text Layers and Saving Files
  4. Using a Text File as a Database
  5. Non-documented functions: Using the Script Listener
  6. Selection of Scripts:
  7. Scripting Limitations
  8. Resources & acknowledgement

I. Preliminary steps

If you have a version of Photoshop CS, you can skip the downloading instructions below, since the scripting plug-in is installed with CS by default. The tutorial uses scripting with Photoshop 7 – some scripting capabilities have been improved since then, so don’t be alarmed if you CS version can do in two steps what I’ve scripted in ten :P… And, on a sidenote,

Downloading instructions: you can download the plug-in for version 7 of PS on Adobe’s web site by searching for ‘scripting plug-in’ – the latest links were here (for Mac) or here (for PCs). Installation will create a ‘Scripts’ folder in the ‘Presets’ folder of photoshop.

I recommend making a shortcut to this folder (and the scripting documentation folder) which you might use often

Getting familiar with scripting: you can now check your scripts; which you can test by using the menu File>Automate>Scripts (you can try to alt/apple click in the dialog box to run your script with a debugger)

I also recommend recording an action, in which you play your test script, and binding a key to this action. In this way all you’ll have to do to test your script is press the magical key.

  Edit your scripts with simple text applications (textpad) otherwise Photoshop might have trouble processing them …

I will use ONLY JavaScript in my examples because it’s the only cross-platform language. Keep in mind that the same scripts can be written in VBScript and Applescript (and much more, since you can script more applications and call them from these scripts, and not in JS) but the syntax is a bit different (check the doc for changes).

Final Preliminary Note

Before asking questions or quitting in despair because you can do what you want – READ the doc given with the scripts, although it’s incomplete in some places, it will give you a good feel of scripting and is very important for syntax/references/methods etc… Make sure to check the sample scripts (provided with the plug-in) and look at their respective codes to see which method does what… This tutorial is a re-hash of all these codes, plus extra scripting.

The scripts have not all been tested with Photoshop CS or Mac-based machines. If you cannot figure out why your scripts don't work; check the end of the tutorial to contact me, and I will try to update the scripts as soon as possible !


And on we go to scripting... next step: Documents and Layers


 page 1 / 11