applescript - 使用 AppleScript 更改屏幕分辨率

标签 applescript system-preferences

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

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

最佳答案

单选按钮是单选组的一部分。单选按钮组是选项卡组的一部分。

这是脚本:

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

关于applescript - 使用 AppleScript 更改屏幕分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37014276/

相关文章:

macos - 如何从 SwiftUI View 中运行 AppleScript?

cocoa - 在 AppleScript 中调整不可编写脚本的应用程序的窗口大小

ios - 如何在 iOS 键盘键上显示美国手语 (Hand Signs)?

cocoa - 从 cocoa 编辑系统偏好设置

c - 是否可以/安全地以编程方式更改 OSX 鼠标系统首选项设置(例如跟踪速度)?

objective-c - 将 Applescript 移植到脚本桥 : can't get value of range in Excel 2008

bash - osascript语法错误 “Expected expression but found end of line. (-2741)”

macos - 用于运行检测显示器的 Applescript

macos - 在 El Capitan 中以编程方式打开某些 OS X 首选项面板