I am trying to click at radio buttons in Displays panel of System Prefernces. This is the code I use to identify radio buttons:
tell application "System Preferences"
activate
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
end tell
tell application "System Events"
tell application process "System Preferences"
set frontmost to true
get every radio button of window 0 // returns {} -> empty array
end tell
end tell
The radio buttons returned are none. Based on what I see, window has zero radio buttons. This leads to a conclusion that radio buttons are part of sub window, namely the Displays subwindow and not the main window. How can I navigate to this "subwindow" and click radiobuttons?
Best Answer
The radio buttons are contained within a radio group, and the radio group is contained within a tab group. So the following code will give you the names of the radio buttons.
You also need to put in a delay between opening the window and trying to talk to it. Even on an SSD equipped Macbook Pro. You might have to increase the delay if you are on an HDD equipped Mac.
Also for the sake of brevity I've swapped the line
set current pane to pane "com.apple.preference.displays"
forreveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
.If you are trying to work out how a user interface is assembled a very useful tool is "Accessibility Inspector". Just launch it and it will float above your windows. Then point your cursor at whatever you want to understand and it will show you the hierarchy of how the user interface components are assembled.