Photoshop scripting offers a more powerful automation technology than actions. Scripts allow for the execution of more elaborate tasks than what actions can do. This is because scripts recognize conditional states. Scripting was introduced in Photoshop CS, and powerful built-in scripts automate the processing of multiple layers or layer comps.
Fortunately, there are some wonderful examples of scripting available at the Adobe Studio Exchange Web site (www.adobexchange.com). Be sure to look for scripts by Photoshop guru Russell Brown. Load new scripts by choosing File > Script > Browse. To permanently add a script to the Script menu, copy it into the Scripts folder inside your Presets folder. For now, let's explore the built-in scripts.
Export Layers to Files
There are certain production situations where it is useful to export a layered PSD file to separate images. This might be the case if you are trying to bring a layered file into another application that does not read layered files.
Photoshop allows you to convert a layered file into a series of individual files. You can choose to create a PSD, BMP, JPEG, PDF, Targa, or TIFF for each layer. Layers are named automatically as they are created; however, you have some options you can modify for naming. Let's give it a try:
DVD Slide Show
Open the file Script Sample.psd
Choose File > Scripts > Export Layers To Files.
In the Export Layers To Files dialog box, choose Destination by clicking Browse. For our sample, create a folder on the desktop called Script Export.
Enter a name in the File Name Prefix text box. This will serve as a prefix for the exported files.
Choose a File Type and set options for the exported file. For our sample choose PSD.
Select the Visible Layers Only option if you only want to export layers that have visibility enabled.
Choose the Include ICC Profile option if you want the working space embedded in the exported files. This is important if you're working in a color-managed workflow.
The Image Processor command can be used to convert and process multiple images. It made its official debut in Photoshop CS2, but you can find it at Adobe Studio Exchange under the name Dr. Brown's Image Processor. (If you're still using Photoshop CS, you can download and use version of this useful script.)
The Image Processor differs from the Batch command in that you don't have to first create an action. The image processor can be used for any of the following tasks:
To convert a set of files to JPEG, PSD, or TIFF format. You can also convert files simultaneously to all three formats.
To process a set of camera raw files using the same camera raw options.
To resize images to fit within a specified pixel dimension.
To embed a color profile into images or convert files to sRGB and save them as JPEG images for the Web.
To include copyright metadata into the processed images.
The Image Processor works with PSD, TIFF, JPEG, or camera raw files.
Tip: Apply One Setting to All
If you need to process a group of camera raw files taken under the same lighting conditions, open and adjust only the first image to your satisfaction. You can then apply the same settings to the other images by checking this option's box.
Choose > File > Scripts > Image Processor.
Choose the images you want to process. You can use open images or navigate to a folder to choose images. Click Select Folder and navigate to the folder called Batch 1 in the Chapter 15 folder.
Select a location to save the processed files. You can choose the Script Exports folder on the desktop.
Select the file types and options you want to convert to: For our example, choose JPEG and choose to resize to 800 x 600 pixels with a compression of 10.
You can choose other processing options as well:
- Run Action: If an action is loaded into Photoshop, you can run it on the image during the process.
- Copyright Info: This includes any text you enter in the IPTC copyright metadata for the file. Text overwrites the copyright metadata in the original file.
- Include ICC Profile: This embeds the color profile with the saved files.
Tip: Saving Settings
You can click Save to save the current settings in the Image Processor dialog box. These settings can be reloaded for a later job if needed. For our example, choose an Image action to run on the processed images.
Click Run. Photoshop processes the images to the specified folder.
Layer Comps to Files, PDF, and WPG
Three scripts work with Layer Comps. Layer Comps allow you save different arrangements of layer visibility, position, and effects. Layer Comps are covered in depth in Chapter 8.
Open an image that uses Layer Comps. You can use your own or the file called Script Sample.psd from the Chapter 15 folder.
You have to choose from three different ways to export layer comps. Choose File > Scripts and then choose one of the following scripts:
- Layer Comps To Files: This exports all layer comps to individual files, one for each comp. You can choose to create BMP, JPEG, PDF, PSD, Targa, or TIFF files.
- Layer Comps To PDF: This places all layer comps into a PDF file. This is a useful way to send a layer comp set to a client for review. The options are identical to the PDF slide show command.
- Layer Comps To WPG: This creates a Web Photo Gallery from each layer comp. By default, the style is set to Simple for the gallery. You can change the style, but must do so manually (there's no pop-up list). Just copy the name of the Web gallery style; you can navigate inside your Photoshop application folder (Photoshop > Presets > Web Photo Gallery). Copy the exact name of a template and paste it into the style box.
Script Events Manager
Let's create a useful script that resets Photoshop's interface on launch. This can be particularly useful in a mixed user environment like a computer lab.
Call up the Actions palette.
Select the Default Actions set (if its not loaded, choose it from the Actions palette submenu).
Create a new action called Reset.
Choose Window > Workspace > Default Workspace. Photoshop resets all of the palettes and tools.
Select the Actions palette and click Stop.
Select the Default Actions set and save it back into your Presets folder (overwriting the previous version).
We can now set up an event and an action to go with that event.
Choose File > Scripts > Scripts Events Manager.
Make sure the box Enable Events to Run Scripts/Actions is checked.
From the Photoshop Event menu, choose an event that will trigger the script or action. For our example, choose Start Application as the event.
You can choose to add a script or an action. In this example, choose the newly created Reset action from the Default Actions folder.
Click Add. The event and its associated script or action is now listed in the dialog box.
When you're finished, click Done. The dialog window closes. The Reset script will run each time you launch Photoshop.
Tip: Disable or Remove Events
To disable or remove individual events, call up the Script Events Manager. Select the event in the list and click Remove. To disable all events but still keep them in the list, you can deselect Enable Events To Run Scripts/Actions.