Creating an action with a modal control

Actions register not just the dialog boxes you bring up while recording, but the exact settings you assign to them as well. There may be times, however, when you'll want to create an action for tasks that require you to change these values on a per-image basis. Photoshop allows you to enable what's called a modal control to pause the action at the point where you need to enter your alternative settings.

Modal controls can also be used with tools such as Crop or Transform that require you to commit to a task before it is applied. With a modal control enabled, the action will pause so you can alter the adjustment you performed when recording the action. And as soon as you commit to your new adjustment (usually by clicking OK or pressing Enter/Return) the action resumes running. Confused? Don't worry. This is much easier to demonstrate than explain, as you'll see in the example below.

Here’s an action to crop an image in a way that will extend the canvas, automatically filling in the empty areas using Content-Aware Fill. First, open an image and click the New Action button as described earlier. Begin recording and do the following:

1. Double click on the background layer to unlock it. Click OK in the dialog that appears. 2. Choose the crop tool and draw a crop. Click at least one edge of the crop and extend it beyond the edge of the image. Press Return/Enter to apply the crop.
3. Hold down the Cmd/Ctrl key and click the image icon in the layers panel. This selects all of the image pixels on the layer. 4. Go to Select>Inverse to select the transparent pixels. Then go to Select>Modify>Expand and enter a value of 3. Click OK.
5. Go to Edit>Fill>Use Content Aware and click OK. 6. Go to Select>Deselect to remove the marching ants and press the Stop button to end the recording.

The problem with this action is that, when applied to other images, the crop dimensions will always be identical to those when we created the action. To gain the ability to customize the crop for different images we need to add a modal control. And it couldn't be simpler to do.

Go to the Actions panel and open the disclosure triangle to display all the steps in the action. Click in the empty box next to the Crop step. A grey icon appears (highlighted here in red), which indicates the action will pause at that step.

The next time you run this action it will pause after the crop is drawn, allowing you to adjust it however you wish. As soon as you commit to the crop, the action automatically resumes, performing the rest of the steps. Pretty slick!

After trying out this action on your own images you'll soon realize that Content Aware Fill is not perfect. Although it attempts to 'intelligently' choose areas from which to sample - and will vary its sampling area on successive attempts - the more detailed the background you're expanding and/or the larger the expansion you specify, the greater the chance the image will need some extra attention afterwards. In my image the left side of the image showed obvious defects. I needed to manually use the healing and clone tools to get the result you see below.

Here is the original image. After the action is run, the image canvas is extended slightly along the left side and bottom of the frame.

Click here to continue reading our Automating Photoshop article...