Dec 12, '11 07:30:00AM • Contributed by: squalene
Apple's Accessibility Inspector.app, which comes with Xcode, is some help with this, but in my hands, it's always been awkward to use for figuring out what code I need to write to click a particular check box in say, a System Preferences Pane.
Here's a bit of AppleScript I wrote years ago that delivers up easy to understand and correct lists of an application's window and menu items in a format that may easily be cut and pasted directly into Scripts.
-- Entire Contents Demo - mini -- BP ages ago or so -- This'll get all the controls and structures associated with an App's window and menus -- In a form which is easily pasteable into your own scripts -- and show them in the result pane below. -- -- Copy that into a text editor and change commas to returns to get an easily readable list. -- -- The script can take a long time if there are LOTS of window items, such as -- in the "music" pane of iTunes. It may even time out if you have a huge iTunes library -- The script'll process most App's UI structures in under a minute set appname to "System Preferences" -------------------------- Set this to the App you want to look at set winstuff to "defaultval" set menustuff to "defaultval" tell application appname activate end tell tell application "System Events" tell process appname set winstuff to entire contents of front window set menustuff to entire contents of menu bar 1 end tell end tell --return winstuff & "rrrr" & menustuff -- comment this out to get just winstuff return winstuff -- comment this out too to get just menustuff --return menustuff
slider 1 of group 1 of tab group 1 of window "Desktop & Screen Saver" of application process "System Preferences" of application "System Events"
tell application "System Events" set value of slider 1 of group 1 of tab group 1 of window "Desktop & Screen Saver" of application process "System Preferences" to 180 end tell
I've looked for similar code online, and it doesn't seem to be commonly available.
[crarko adds: I tested some of this out; as mentioned, be prepared to do some massaging of the data that is returned (in AppleScript Editor's Results window) to make it readable.
Note: comments indicate this also works in versions before Lion.]
