2016-05-03 121 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