Automating Photoshop with JavaScript (Advanced)

By Josh Wright on March 2011 in tips


I've been working to automate Photoshop quite a bit lately. In September I wrote Automate Photoshop with JavaScript which uses ExtendScript Toolkit (packed with Photoshop CS5). Then in January I wrote

Automating Photoshop With C# which uses a COM reference to control Photoshop from another program.

The documentation for scripting with CS4/CS5 is pretty decent, covers a lot of areas, and has worked great for me until today.

Doing Something "Advanced"

Today I needed to add a black "Color Overlay" to a layer. To do this manually, I would:

1) right-click a layer and choose "Blending Options"

2) check "Color Overlay"

3) choose the color

4) press "OK"

I soon found that blending options and color overlays are not covered in the 233 page doc. But wait... they can be automated (with PS actions) so it seems like I should be able to script it.

Creating a Script from an Action

If you've got an action then you can easily create a script from it. Just copy & paste this script into ExtendScript Toolkit. (If you don't know what ESToolkit is, check out this post)

When you run that script, it creates a little dialog where you select your action. Once you're finished, the script will be saved to your desktop.

This method actually has different, better results than the next one.

Create a Script from What You Do

There's also a nice little plug-in that comes with CS5 that lets you just work in Photoshop as normal and it creates a script as you work. See the link for details, but installation worked like this for me:

1) Copy C:\Program Files\Adobe\Adobe Photoshop CS5\Scripting\Utilities\ScriptListener.8li into C:\Program Files\Adobe\Adobe Photoshop CS5\Plug-ins\Automate

2) Restart Photoshop

This automatically creates two files on your desktop: ScriptingListenerJS.log and ScriptingListenerVB.log which contain the JavaScript and VBScript scripts as you work.

Don't leave it turned on forever. You'll build up very large log files as you work and it may slow you down.

To uninstall, just delete ...\Utilities\ScriptListener.8li

In some cases, you will do something that will not generate any code script. In these cases, use the previous section (converting actions to scripts) since it has better results.