问题
I am trying to click at radio buttons in Displays panel of System Prefernces, namely to change Screen resolution. 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
--click button 1 of window 0 of application process "System Preferences" of application "System Events"
--click radio button "Scaled" of radio group of window "com.apple.preference.displays"
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?
回答1:
The radio buttons are part of the radio group
. The radio group is part of the tab group
.
Here's the script:
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
tell tab group 1 of window 1
click radio button 2 of radio group 1 -- "Scaled"
select row 2 of table 1 of scroll area 1 -- select the second row in the table to change the resolution of the monitor
end tell
end tell
end tell
来源:https://stackoverflow.com/questions/37014276/change-screen-resolution-with-applescript