OS X Accessibility Inspector (UIElementInspector) Tool for UI Scripting

The Accessibility Inspector is also contained in Xcode, in case you have it already installed. Menu bar: Xcode > Open Developer Tool > Accessibility Inspector. (You can also launch it through Spotlight without Xcode, it’s in /Applications/Xcode.app/Contents/Applications/)

One problem with the Accessibility Inspector is that often it doesn’t provide you with the exact terms (UI element names) you need for a working UI script.

For example recently I had the problem to get the name of a selected reminder in the Reminders app. The correct “path” is this one:

text field 1 of UI element 1 of (rows whose value of attribute "AXSelected" is true) of table 1 of scroll area 1 of group 1 of splitter group 1 of window "Reminders"

But, as I first checked the reminder with Accessibility Inspector I couldn’t find all of the needed names of the elements. Some names correspond to the ones from accessibilityRoleDescription in Accessibility Inspector, for example table, scroll area, but others don’t (UI element 1, group, splitter group).

To get the correct element names for your script you have to query for UI elements, for example like this:

tell application "System Events"
	tell window "Reminders" of process "Reminders"
		UI elements
	end tell
end tell

This gives you {splitter group 1 of window "Reminders" of…etc. Then you have to repeat the same with tell splitter group 1 of window "Reminders" of process "Reminders" to get the next object, and so on. This way you get the correct (= usable) element names. It’s very well explained here.

Fortunately some friendly people have posted a script in the MacScripter forum that gives you the complete structure (with usable element names) of a given process in one go. (There are several versions of the script in the thread. I think the best one is the script in post #33.)

2 Likes