change screen resolution with AppleScript

て烟熏妆下的殇ゞ 提交于 2019-12-08 06:35:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!