Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Adobe Photoshop

  • Print
  • + Share This
From the author of

Actions and Scripting

The trick to being really productive and efficient with computer technology is to be lazy. Yes, it’s a paradox, but it’s true; the lazier you are, the more likely you are to find the really efficient ways of doing things so you can get out of work faster and go to the beach.

Photoshop offers four automation features: actions, Automate, Variables, and scripting. Actions live in the Actions panel and let you repeat a series of steps, similar to the macros you may have used in office programs. Photoshop ships with a number of premade actions, and you can easily build your own (we’ll show you how). Automate refers to the built-in tools in the File > Automate submenu such as Batch and Photomerge; we’ve chosen to cover them where they apply. Variables provide a way to create a template image that changes depending on data imported from a spreadsheet or a database; because they’re used primarily in Web design, we don’t cover them in this book. Scripting automates Photoshop from behind the scenes using AppleScript, JavaScript, or Visual Basic. We’ll look at aspects of actions and scripting that we haven’t yet covered.

Actions

In Chapter 5, we discussed some of the basics of building actions—particularly actions that help in the processing of raw files. But Photoshop also comes with a number of premade actions that are not only useful but educational, because you can look at them to see how they produce their magic. (You can load additional sets of actions by selecting Load Actions from the Actions panel menu, or by choosing the presets that appear at the bottom the panel menu.)

The key is that you can make an action only for something you can do blindly, with no feedback from the program, and with little or no brain activity. For example, you can’t record an action that says, “If the pixels in the upper left corner of the image are sort of reddish, then do such-and-such.” Photoshop would have to be able to see and respond. No can do.

However, you can easily create an action that runs a particular set of Curves, adds a text layer, adds a layer effect, sharpens the background layer, and so on, because all these things are methodical.

Action Limitations. Before you get too heady with your newfound actions power, you should know that Photoshop doesn’t let you record everything you might want. Although you can record blending modes, opacity, shapes, brush selections, and even pixel selections, you still cannot record brushstrokes (such those made with the Brush, Airbrush, and Clone Stamp tools), zooms, window switching, and scrolls. And there are many features that aren’t necessarily record able but that you can force into an action (see “Editing Actions,” later in this chapter). Last but not least, the whole Actions mechanism has a logic unto itself. If an operation isn’t recordable by keyboard shortcut, it may be recordable by choosing the menu command instead, or vice versa.

Planning Your Actions

Besides the limits of what you can and cannot record in the Actions panel, there are a few more things to keep in mind when planning actions.

Difficulty. While recording and playing simple actions (those with only two or three steps) may be easy, trying to build complicated actions can be damaging to your head (and the wall you’re banging it against).

Modularity. Rather than trying to make one big action that does everything you want, break it down into smaller steps that you can debug individually and then chain together to reuse in more complex actions.

Think It Through. You should always think the action through completely before you start recording it. You might even write down each step on paper, and then record it after you’re pretty sure everything will work out the way you want.

Generic Actions. Try to make your actions as generic as possible, because there are many specifics that can trip up an action and result in an error. Actions should be able to run on any image at any time. There are a number of things to think about when making your actions generic. The following list is a good place to start:

  • Never assume image mode. The image may be in RGB, CMYK, Grayscale, or even Indexed Color mode. This is very important when running filters, because some filters don’t run in certain modes. You may want to add a step that converts to your intended mode.
  • Don’t assume the image has layers (or doesn’t have layers). Also, don’t assume that if the image does have layers, the Background layer is selected (or even that there is a layer called Background). If you need the lowest layer selected, press Option-Shift-[ (Mac OS X) or Alt-Shift-[ (Windows). You may want to add a step that flattens an image.
  • Avoid using commands that pick layers by name, unless the action creates and names the layer or you are certain the files will always contain a particular name. For example, if you record clicking on a layer in the Layers panel, Photoshop records the click by layer name, not position. Instead, record pressing Option-[ or Option-] (Mac OS X) or Alt-[ or Alt-] (Windows) to target the next layer down or the next layer up, respectively. Command-[ and Command-] (Mac OS X) or Ctrl-[ and Ctrl-] (Windows) move layers up or down, respectively.
  • If you’re saving and loading channels, you’ll almost certainly have to name the channels. Make sure you give them names that are unlikely to already be present in the image. Do name them, though, rather than leaving them set to the default names like “#4”. If a document has two channels with the same name when you run an action, Photoshop always uses the first channel with that name.

Alternatively, you can provide the user with a message at the beginning of the action noting what kind of image is required (as well as other requirements, such as “needs text on a layer” or “must have something selected”). This is a good idea even if you’re the only one using your actions, because (believe us) after you’ve made a bunch of actions, you’ll forget which action requires what (see “Talk to Your Users,” later in this section).

Cleanup. It’s a good idea to make your actions clean up after themselves. In other words, if your action creates three extra channels along the way to building some other cool effect, the action should also probably delete them before ending so that they don’t cause confusion or trip up another action.

Action Basics

Making an action is pretty straightforward:

  1. Open the Actions panel (see Figure 11-36).
    11fig36.jpg

    Figure 11-36 The Actions panel

  2. Click the New Action button (or select New Action from the Action panel menu). Give the action a name (and a keyboard shortcut, if you want). If you have more than one set (see “Sets,” later in this section), choose which set this new action will be part of. When you click OK, Adobe Photoshop begins recording automatically.
  3. Perform the steps that you want the action to do.
  4. Click the Stop button in the Actions panel (or select Stop Recording from the Actions panel menu).

Then, to run the action, select the action’s thumbnail in the Actions panel and click the Run button. Better yet, just Command-double-click (Mac OS X) or Ctrl-double-click (Windows) on the action. If the action is relatively simple, it may perform perfectly the first time. But in most of the actions we make, we find that something goes wrong somewhere along the line, usually due to our performing a step that Photoshop can’t record into an action (see “Troubleshooting Actions,” later in this section).

Save Your Work First. If you run an action and then decide that you don’t like what it did, you’re in trouble, because you cannot undo a full action, only the last step of an action. If the action used only a few steps, you might be able to use the History panel to return to a state before you ran the action, but this isn’t always possible either, particularly if you ran the action as a batch process on multiple files. To guarantee an undo option, we’re in the habit of saving a snapshot of our document in the History panel before running any action. That way, if something goes wrong or we don’t like the effect, we can revert back to this snapshot. Another option is simply to save your document first, and then use the Revert command (in the File menu) to undo the action. Of course, neither of these techniques works with actions that save and close the file—we recommend always making actions that use Save As rather than saving over the original.

Sets. Photoshop lets you create sets of actions, a godsend to anyone who works with dozens of actions. Sets are pretty self-explanatory.

  • To create a new action set, choose New Set from the Actions panel menu (or click the New Set button in the panel). You can delete a set by selecting it and choosing Delete from the same panel menu, or by clicking the Delete button in the panel.
  • To move actions between sets, drag them.
  • To rename a set, double-click its thumbnail in the Actions panel.
  • To show or hide the actions within a set, click the triangle to the left of the set’s name.
  • You can also save sets (see “Saving Actions,” later in this section).
  • To play all the actions in a set (in order), select the set and click the Play button in the Actions panel.

Editing Actions. Once you’ve built an action, you can edit it (in fact, you’ll almost certainly want to edit it unless it worked perfectly the first time). If you want to record additional steps somewhere in the middle of the action (or at the end of the action), select a step in the action and click the Record button. When you’re done recording, click the Stop button. All the new actions fall after the step you first selected.

If you want to add a step that cannot be recorded for some reason (perhaps it’s an item on the View menu), you can select Insert Menu Item from the Actions panel menu. This lets you choose any one feature from a menu, and then inserts it into the action (after the currently selected step).

To change the parameters of a step, double-click on it in the Actions panel. For example, if a step applies a curve to the image (using the Curves dialog), but you want to change the curve, double-click on the step and choose a different curve. Note that when you do this, you may actually change the current image; just press Command-Z (Mac OS X) or Ctrl-Z (Windows) to undo the change (to the image, not to the action).

If you want to change the action’s name, its thumbnail or button color, or its keyboard shortcut, just double-click on the action’s name.

Stop Where You Are. Normally, Photoshop won’t display any of the usual dialogs when you run an action. For instance, if you include a numeric transform step in an action, Photoshop just performs the transform without displaying the dialog. But you can force Photoshop to display the dialog, stop, and wait for the user to enter different settings before continuing. To do so, click once in the second column of the Actions panel, next to the step. A black icon indicating a dialog appears next to the step, and a red icon appears next to the action’s name.

Don’t click on a red dialog icon! If you do, it turns black and Photoshop adds a black “stop here” icon next to every step in the action that can have one. There’s no Undo here, so the only way to reset the little black icons to their original state is to turn them on or off one at a time. (You can, however, turn off all of them by clicking the black icon next to the action’s name.)

Note that if you insert a step using the Insert Menu Item command, Photoshop always opens the appropriate dialog and doesn’t even offer you the chance to turn this icon on or off (because steps inserted in this way are meant to simulate the user actually selecting the item).

Talk to Your Users. You can stop the action at any point and display a dialog with a message in it. This message might be a warning like, “Make sure you have saved your image first,” or instructions such as, “You should have a selection made on a layer above the background.” To add a message, select Insert Stop from the Actions panel menu. Photoshop asks you what message you want to show and whether the message dialog should allow people to continue with the action (see Figure 11-37).

11fig37.jpg

Figure 11-37 Adding a message

If your message is a warning, you should turn on the Allow Continue option, but if you’re communicating instructions, you may want to leave this check box off. When Allow Continue is turned off, Photoshop stops the action entirely. After the user clicks the OK button in the message dialog, Photoshop automatically selects the next step in the Actions panel, so the user can continue running the action by clicking the Run button again (this works even if the Actions panel is in Button mode).

Saving Actions. After you’ve created the world’s most amazing action, you may want to share it with someone else. You can get actions out of your Actions panel and onto your hard drive by selecting Save Actions from the Actions panel menu. Unfortunately, you cannot save a single action; the Save Actions feature only saves sets of actions. The work-around isn’t too painful, however.

  1. Create a new set (click on the New Set button at the bottom of the Actions panel) and name it something logical.
  2. Either move the action you want to save by dragging it, or duplicate it by Option-dragging (Mac OS X) or Alt-dragging (Windows) it into the new action set.
  3. Select the new action set and choose Save Actions from the Actions panel menu.

Of course, you can load sets of actions just as easily with the Load Actions and Replace Actions features in the Actions panel menu. Watch out for Replace Actions and its cousin, Clear Actions; these replace or clear all the actions in the panel, not just the selected one.

Troubleshooting Actions. As we mentioned in Chapter 5, don’t immediately test an action on some mission-critical image. Rather, try it on a dummy image. Even better, try it on several dummy images, each in a different mode (RGB, CMYK, Grayscale, Indexed Color), some with layers, some without, some with selections made, others without, and so on.

Step by Step. You can force Photoshop to pause after each step and redraw the screen by selecting Step by Step in the Playback Options dialog (choose Playback Options from the Actions panel menu). This is often useful, but the best troubleshooting technique in the Actions panel (in fact, probably the only troubleshooting technique) is to select the first item in the action and click the Run button while holding down the Command key (Mac OS X) or Ctrl key (Windows). This plays only the first step. Now go check out all the relevant panels. Is the Channels panel the way you expect it? What about the Layers panel? What are the foreground and background colors? When you’re convinced that all is well, Command-click (Mac OS X) or Ctrl-click (Windows) the Run button again to check the second step in the action, and so on until you’ve tested the entire action. If at any time you find the panels or colors set up improperly, now is the time to replace the last step or double-click on it to change its settings. If something is really messed up, you can fall back on your History snapshot, or revert.

Making Droplets

We’re not sure why the Make Droplet feature is hiding in the File > Automate submenu instead of the Actions panel, but that’s where you can find this really awesome feature. You can use Make Droplet to save any Photoshop action to disk as a file. Then, when you want to process an image (or a folder full of images) with that action, you can simply drag the image (or folder) on top of the droplet file.

If you work in both Mac OS X and Windows, you can copy droplets from one platform to the other. On the PC you simply have to make sure that the droplet has an .exe extension. When you bring a PC droplet to the Mac, you have to initialize it by dragging it on top of the Photoshop application icon, but you have to do that only once.

  • + Share This
  • 🔖 Save To Your Account