DESIGN | Introduction To Photoshop Scripting

Automation is useful in the work of every designer. It saves precious time on repetitive tasks and helps us solve certain problems more quickly and easily.
You can automate your workflow in Photoshop with actions, which are pretty popular and which most of you already know about and use. Today, we’ll introduce you to an advanced automation technique: scripting. All you need for this is basic knowledge of JavaScript, which some of us Web designers already have.
I’ve known about Photoshop scripts for years but decided to really dive in a few months ago. I had avoided it because I thought it was the domain of smart math-minded programmers. I was wrong, and today I’ll show that, although it requires some basic programming skills, scripting isn’t hard to grasp.
But first, we have to answer the obvious question.

Why Do We Need Scripts?

Why should we would learn to script if Photoshop already has pretty nice actions? The answer is interactivity. When you use an action, you can’t really control how it behaves in different situations; it is like a videotape that just keeps playing again and again without any change.
A script is more dynamic; its behavior changes according to the parameters you input or the context of its application. Sounds useful, no?

Requirements

You don’t have to be an advanced programmer to be able to write scripts; I’m just a graphic designer, like most of you. But you should at least have a basic understanding of JavaScript and some experience with properties and methods to get the most out of this article.
If you are not familiar with JavaScript at all, fear not! There are plenty of places to learn the basics of programming. Codecademy, for example, has pretty neat interactive lessons.
I work in Adobe Photoshop CS5, but everything we’ll cover applies to newer versions, too; Adobe hasn’t made any major updates to its scripting API since CS5. I will refer to the latest version of the scripting documentation, though, which is CS6.

Getting Started

When you record actions in Photoshop, you set the order of the steps to achieve a certain result — that’s your algorithm. Then, you press “Record” and replicate them in Photoshop one by one. Scripting is similar, but instead of doing these steps in Photoshop, you write them down as lines of code. Most actions that you do in Photoshop have their own script equivalent as a function.
Let’s say you are creating an action that scales a document to 150% of its original size. You’d go through these steps:
  1. Open Image → Image Size.
  2. Enter 150% in width and height.
  3. Hit “OK.”
The same process with a script would look like this:
  1. Call the application: app
  2. Target a document: activeDocument
  3. Call the function to resize the image: resizeImage(width, height)
And the code would look like this:
app.activeDocument.resizeImage("150%", "150%");

LANGUAGE

There are three ways to write scripts for Photoshop: using AppleScript on Mac,VBScript on Windows or JavaScript on either platform. I use the third because it is cross-platform and I already have some experience with it.

TOOLS

Adobe has its own utility for writing scripts, called ExtendedScript Toolkit.
--- to be continued...

0 comments:

Post a Comment

 

Flickr Photostream

Twitter Updates

Meet The Author

I'm Rendy Andrian. I'm passionate about a lot of things. Especially design and video games. Even more so when they're related.