2016-05-03 123 views
0

我正在尝试单击System Prefernces的Displays面板中的单选按钮,即更改屏幕分辨率。这是我用它来识别单选按钮的代码:用AppleScript更改屏幕分辨率

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 

返回的单选按钮没有。根据我所看到的,窗口有零个单选按钮。这导致一个结论,单选按钮是子窗口的一部分,即显示子窗口而不是主窗口。我如何导航到这个“子窗口”并单击单选按钮?

enter image description here

回答

1

单选按钮是radio group的一部分。收音机组是tab group的一部分。

这里的脚本:

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 
+0

我调整“选择行2 ...”得到它的工作的一部分,否则这是伟大的! – sanjihan