I had a play with @CJK's script. I can get it to return some UI element info, but it only goes as deep as the group level. I have a feeling this might be to do with the multiple layers of nesting going on with the various panes of the System Settings application.
Adjusted Script
use framework "AppKit"
on mouseCoordinates()
tell the current application to tell mouseLocation()'s {x, y} ¬
of its NSEvent & NSHeight(its NSScreen's mainScreen's ¬
frame) to return the {(item 1), (item 3) - (item 2)}
end mouseCoordinates
on infoForUIElementUnderMouse()
return infoForUIElement at the mouseCoordinates()
end infoForUIElementUnderMouse
on infoForUIElement at __Ref
local UIElement
tell application id "com.apple.SystemEvents"
tell process "System Settings" -- Explicitly targeting the System Settings app
if {__Ref}'s specifiers = {} then
tell __Ref to if its class ≠ list ¬
then set __Ref to its {x, y}
set __Ref to click at __Ref
end if
set UIElement to __Ref
if the UIElement = missing value then return {}
script Object
property parent : UIElement
property AXAttributes : a reference to (the ¬
attributes in me whose (name is not ¬
"AXURL") and (name is not "AXPath"))
property AXValues : value of AXAttributes
property AXList : the name of AXAttributes
property AXRecord : a reference to the the ¬
{«class usrf»:my AXList}'s contents
end script
set my text item delimiters to linefeed & linefeed
tell (a reference to the Object's AXList) ¬
to set the contents to paragraphs ¬
of (it as text) & ""
tell the Object to repeat with i from 1 ¬
to the length of its AXValues
set its AXList's item (i * 2) to ¬
item i of its AXValues
end repeat
return {UI element:the Object's contents} ¬
& the Object's properties ¬
& (the Object's AXRecord as any) ¬
& the {_AXActions:the name of ¬
every action in the Object}
end tell
end tell
end infoForUIElement
return infoForUIElementUnderMouse()
Example Script Result (Output Button in Sound Pane)
UI element:group 2 of splitter group 1 of group 1 of window Sound of application process System Settings, minimum value:missing value, orientation:missing value, position:1156, 203, class:group, accessibility description:missing value, role description:group, focused:false, title:missing value, size:499, 625, help:missing value, entire contents:, enabled:missing value, maximum value:missing value, role:AXGroup, value:missing value, subrole:AXHostingView, selected:missing value, name:missing value, description:group, AXFrame:1156, 203, 1655, 828, AXParent:splitter group 1 of group 1 of window Sound of application process System Settings of process System Settings, AXChildren:group 1 of group 2 of splitter group 1 of group 1 of window Sound of application process System Settings of process System Settings, AXSize:499, 625, AXFocused:false, AXRole:AXGroup, AXTopLevelUIElement:missing value, AXHelp:missing value, AXChildrenInNavigationOrder:System Events, AXPosition:1156, 203, AXWindow:window Sound of application process System Settings of process System Settings, AXRoleDescription:group, AXSubrole:AXHostingView, _AXActions:
This is the tell block produced by my macro using this adjusted script:
activate application "System Settings"
tell application "System Events"
tell process "System Settings"
click group 2 of splitter group 1 of group 1 of window "Sound"
end tell
end tell
As you can see, it starts from a superficial group level. Here's what UI Browser gives me, for comparison:
activate application "System Settings"
tell application "System Events"
tell process "System Settings"
click radio button 1 of tab group 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Sound"
end tell
end tell