【发布时间】: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