Other Applications in Automation Scripts

Automating the workflow for a publication does not always begin and end with a script targeted to Adobe InDesign. The need to involve another application can be as simple as working with the Finder. On the other hand, a script may become a little more involved if the functionality of an application such as Photoshop is required.

As an example, a publication I have been working with is using an internet provider to supply image content for its publication. The images are all the same size and do not need cropping. But, for the purpose of the publication, they need to be resized and saved as CMYK and JPEG. The workflow originally included bringing each of the five images into Photoshop manually, resizing, and then placing the images into an InDeisgn document. The images are stacked vertically from the bottom left of the page. The layout design required that the images have a space (gap) of 12 points between.

This is not a lot of work for one or two images, but when multiplied by many images and many editions, the task was becoming a good candidate for an automation script.

AppleScript Script

Creating the script using AppleScript was the immediate answer since only Macintosh is being used. Also, because applications in AppleScript are called within the script (using a tell statement), a single script could be used that would first activate Photoshop and later, once the images were saved in the appropriate folder, InDesign would take over.

The workflow would expect a pre-defined folder to exist and the target InDesign document to be open when the script is run. Also, the original images for manipulation and placement would be in the Downloads folder for the user. The outline for the script is as follows:

  • check for active document
  • create variable to reference the downloads folder (alias)
  • have the user select the files using the downloads folder reference (list)
  • set up a variable to reference the target folder for saving the manipulated images (string)
  • call a Photoshop handler to process the files chosen and return the resulting list (processedList)
  • call an InDesign handler to place the files and return number of files placed
  • report number of files placed

In the Photoshop handler

  • activate Adobe Photoshop and set it measurement units appropriately (inch units were used)
  • set the properties for saveOptions (class:JPEG save options, quality:10)
  • repeat through the list of files chosen by user
    • within the repeat, get the information for each file (name, file extension, containing folder)
    • set a variable to the path for saving the file using the file’s name
    • open the file and change its mode to CMYK and resize the image
    • save the document and save its new file reference in a list (processList)
    • close the document
  • when through, reset the ruler units for Photoshop to its original setting

Note: When resizing an image in Photoshop, if you want the resized image to keep its aspect ratio, set only one of its dimensions (width or height). If you set both dimensions the resulting image could end up distorted.

One potential problem that needs to be checked within the handler is the color mode of each file. A grayscale or bitmap image cannot be converted to CMYK, consequently that would raise an error. To check for this, the following is used after the file is opened:

—values for newWid and newRes are passed as part of the call to the handler
tell application “Adobe Photoshop CC 2014”
   tell current document
      if not (mode is grayscale or mode is bitmap) then
         change mode to CMYK
      end if
      resize image width newWid resolution newRes resample method automatic
   end if
end tell

Preset Values

Because this script was written for a specific purpose, values for variables such as the resized width of the images, save quality, file name extension, and gap between placed images were all defined at the top of the script. Should the script need to be used for a variety of situations, a custom dialog could be added with input values defaulting to the most used values.

Running the Script

The script was placed in the Scripts Panel folder for InDesign and given a keyboard shortcut. With the target document open in InDesign the keyboard shortcut is used to launch the script. The user then selects the images to be used from the source folder (Downloads folder). The script does the rest. The amazing thing for me is to see how quickly the computer can run through all of the code. For the client, well he was amazed to see the process completed in less than a minute where it used to take the better part of an hour to process and place the files.

Sample Script

You can check out the entire script, ResizeSaveJPEG, which can be downloaded from our AppleScript page. You may find some code in this script that you can adapt to automate one of your own workflow issues involving Photoshop.