Applescript GUI Scripting Workaround

We routinely use Applescript to automate our workflows. After upgrading a system to OS X Yosemite a script we use with an older version of Photoshop no longer worked. The script was failing on the Photoshop standard commands copy and paste, with the error

"…Photoshop must be the front application when trying to cut, copy or paste"

Since Photoshop was the front application there is clearly a bug or incompatibility with OS X 10.10. The workaround was to use Applescript GUI scripting. This Accessibility feature allows you to post events to mimic a user action. In this case the selection of an Edit menu item. Example of the workaround

  copy selection of current document

was replaced with

  tell application "System Events" to tell process "Adobe Photoshop"
    click menu item "Copy" of menu 1 of menu bar item "Edit" of menu bar 1
  end tell

TechNote #30

Parametric Image Color Table

In a parametric image a pixel’s numeric value corresponds to a physical property (e.g., sea surface temperature, glucose metabolism). Parametric images often use indexed color PNG and GIF file formats. When the image is displayed the pixel value is used as an index to a RGB color in the file’s color table.

If you need to create a custom color table for an image one approach is to use Photoshop. An Adobe Color Table file (.act) is 768 bytes. This corresponds to 256 RGB values with 1 byte per primary color. The first byte in an .act is the red value of index 1. The last byte is the blue value of index 256. To change an image’s color table in Photoshop select Image -> Mode -> Color Table… -> Load…

You can create a Adobe Color Table file using a programming language. Given an ascii text file of RGB values, separated by whitespace, with one RGB triplet per line, a bash shell (OS X Terminal) alternative is


cat color_table.txt | while read rgb
  for v in $rgb
      echo -ne '\x'$(printf "%x" $v) >> custom.act

TechNote #15