【问题标题】:change screen resolution with AppleScript使用 AppleScript 更改屏幕分辨率
【发布时间】:2020-06-10 22:28:52
【问题描述】:

我正在尝试单击系统偏好设置的显示面板中的单选按钮,即更改屏幕分辨率。这是我用来识别单选按钮的代码:

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

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

【问题讨论】:

    标签: applescript system-preferences


    【解决方案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
    

    【讨论】:

    • 我调整了“选择第 2 行...”部分以使其正常工作,否则这很棒!
    • @sanjihan - 你能详细说明“调整”是什么意思......你改变了什么?
    【解决方案2】:

    对于 Mac OS 10.15,您将需要它。

    将“q”设置为您想要的显示按钮首选项 (1-4)

    set tabNum to q as number
    
    tell application "System Preferences" to reveal pane "com.apple.preference.displays"
    
    tell application "System Events" to tell process "System Preferences"
    
        set activeWindow to window 1
    
        repeat until exists activeWindow
        end repeat
    
        set tabGroup to tab group 1 of activeWindow
    
        tell tabGroup to click radio button "Scaled"
    
        set subGroup to group 1 of tabGroup
    
        set radioGroup to radio group 1 of subGroup
    
        tell radioGroup to click radio button tabNum
    
        --log activeWindow
        --delay 0.5
    
        tell application "System Preferences"
            quit
        end tell
    
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多