MacOS Ventura自动切换灰度模式问题求助
解决MacOS自动切换灰度滤镜的AppleScript报错问题
错误原因分析
你的脚本针对的是旧版MacOS(使用System Preferences),而Ventura及以后的MacOS已改用System Settings,导致脚本中应用名称、UI元素定位完全失效,这是触发「AppleEvent例程错误」的核心原因。此外,新系统的辅助功能设置界面结构也发生了变化,原脚本的控件路径已不再适用。
修正后的AppleScript代码
以下是适配新版MacOS的脚本,可直接在Automator的「Run Apple Script」中使用:
-- 关闭已运行的System Settings if running of application "System Settings" then try tell application "System Settings" to quit on error do shell script "killall 'System Settings'" end try end if repeat while running of application "System Settings" is true delay 0.01 end repeat -- 打开辅助功能的显示设置面板 tell application "System Settings" activate reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess" end tell -- 等待界面加载并切换灰度选项 tell application "System Events" to tell process "System Settings" repeat until exists checkbox "Use grayscale" of group 1 of group 2 of scroll area 1 of window "Accessibility" delay 0.01 end repeat click checkbox "Use grayscale" of group 1 of group 2 of scroll area 1 of window "Accessibility" end tell -- 关闭System Settings tell application "System Settings" to quit
关键注意事项
- 权限确认:确保已在「系统设置 > 隐私与安全性 > 辅助功能」中勾选Automator、Terminal,以及你用来运行脚本的其他工具(如Script Editor)。
- 测试脚本:先在Script Editor中运行脚本验证功能,再放到Automator中使用,避免Automator的环境问题。
- 网站触发逻辑:若要实现「访问特定网站时自动切换」,可结合Safari的自动化规则(如使用「快捷指令」监测当前标签页URL,匹配时运行该脚本),或使用第三方浏览器扩展触发脚本执行。
内容的提问来源于stack exchange,提问作者KonstiR
相关产品推荐
相关产品推荐

