【问题标题】:Change MacBook screen scaling via AppleScript通过 AppleScript 更改 MacBook 屏幕缩放比例
【发布时间】:2022-02-17 08:14:35
【问题描述】:

我正在尝试通过 AppleScript 更改 MacBook Pro 14 的比例设置。
该设置应切换两个分辨率设置。
我在这里找到了以下脚本:https://stackoverflow.com/a/62664159/15705553

on run {input, parameters}
    
    tell application "System Preferences"
        reveal anchor "displaysDisplayTab" of pane "com.apple.preference.displays"
    end tell
    
    set lowResolutionSettingIndex to 4
    set highResolutionSettingIndex to 5
    
    tell application "System Events" to tell process "System Preferences" to tell window "Built-in Retina Display"
        click radio button "Display" of tab group 1
        click radio button "Scaled" of tab group 1
        tell radio group 1 of group 1 of tab group 1
            set isHighResolutionSet to get value of radio button highResolutionSettingIndex
        end tell
        if isHighResolutionSet then
            -- Toggle native resolution
            click radio button lowResolutionSettingIndex of radio group 1 of group 1 of tab group 1
        else
            -- Toggle Default setting - "Retina optimized"
            click radio button highResolutionSettingIndex of radio group 1 of group 1 of tab group 1
        end if
    end tell
    
    quit application "System Preferences"
    
    return input
end run

我将“内置 Retina 显示屏”更改为“内置 Liquid Retina XDR 显示屏”,如系统偏好设置中所示,但出现两个错误:

  • 如果我通过 Automator 执行此脚本,则会收到以下错误:
Syntax Error: System Events got an error: Can’t get window "Built-in Liquid Retina XDR Display" of process "System Preferences".
  • 如果我通过 shortcuts.app 执行它,我会收到以下错误,即使我在系统偏好设置中授予了对快捷方式辅助功能的访问权限
System Events got an error: Shortcuts is not allowed assistive access.

【问题讨论】:

  • 您是如何授予对辅助功能的访问权限的?
  • @Philippe System Preferences > Security & Privacy > Privacy > Accessibility > + > Shortcuts.app 在执行脚本之前我对 Automator 做了同样的事情,在这里它起作用了(至少可访问性)。
  • 您是否授予对“脚本编辑器”的访问权限?
  • 最初没有。现在我做到了,重新启动 Automator 和快捷方式,尝试运行脚本,但错误仍然存​​在。

标签: macos applescript


【解决方案1】:

以下是我如何选择列表中的第一台显示器(Macbook Pro 内置 Retina 显示器)以访问屏幕缩放等设置:

tell application "System Preferences"
    activate
    reveal anchor "universalControlTab" of pane id "com.apple.preference.displays"
end tell
tell application "System Events"
    tell application process "System Preferences"
        tell window "Displays"
            select row 1 of outline 1 of scroll area 1 of sheet 1
        end tell
    end tell
end tell

如果您想访问这些设置,请选择列表中的第二台显示器:

tell application "System Preferences"
    activate
    reveal anchor "universalControlTab" of pane id "com.apple.preference.displays"
end tell
tell application "System Events"
    tell application process "System Preferences"
        tell window "Displays"
            select row 2 of outline 1 of scroll area 1 of sheet 1
        end tell
    end tell
end tell

干杯。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-27
    • 2019-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    相关资源
    最近更新 更多