Accessibility Inspector

The hardest thing about GUI scripting in AppleScript is figuring out how to address the various controls on the screen. The class names of standard buttons, text fields, and menus are fairly easy to remember, but the more exotic controls can be tricky. Apple provides a little application that can be a big help with those less common GUI elements.

It’s called Accessibility Inspector, and it used to come with the Developer Tools. You could find it in the Accessibility Tools folder buried deep within the Developer folder.

Accessibility Tools

Depending on the version of Xcode you have, it may still be there. If you’ve upgraded to Xcode 4.3, it might be in the same place, but with the top-level folder renamed to Developer-old. If you don’t have it at all, you can get it from this developer downloads page in the Accessibility Tools section.

The Accessibility Inspector isn’t a particularly nice-looking app. It has a single window that lists the attributes and hierarchy of whatever GUI element is under your mouse. I used it yesterday as I was writing my blurring scripts. For example, Acorn’s Fill… command brings up a window with a couple of popup menus. I tried referring to them in my script as popup menu and popup button, but AppleScript didn’t understand either of those names. With Accessibility Inspector, I quickly learned—from the entry for AXRoleDescription—that the correct term is pop up button—three words, not two.

Accessibility Inspector

(You can see a bigger version by clicking on the image to go to its Flickr page.)

I also learned that the Blending pop up button didn’t have a name. See the “Missing value for AXTitle” down near the bottom? That meant I’d have to access the pop up button by number rather than name. Since it was the second of two such controls in the window, I tried

tell window "Fill"
  tell pop up button 2
    click
    click menu item "Lighten" of menu 1
  end tell
  click button "OK"
end tell

and it worked. If it hadn’t—and I don’t believe there’s any requirement for controls to be numbered from top to bottom—I would have tried 1 instead of 2.

Note also from this snippet of code that the window, the menu item, and the button all did have names and could be addressed as such.

I learned about the Accessibility Inspector from Matt Neuburg’s AppleScript: The Definitive Guide. It’s a handy thing to know.