如何编写适配macOS 13 Ventura的AppleScript系统设置导航代码?
macOS 13 Ventura 系统设置自动化脚本适配方案
macOS 13 Ventura 把原「系统偏好设置(System Preferences)」替换为「系统设置(System Settings)」,原AppleScript API不再兼容,导致旧脚本触发execution error: System Settings got an error: AppleEvent handler failed. (-10000)错误。以下是适配方案:
基础适配代码(仅Ventura)
直接通过系统URL Scheme定位到目标设置面板,这是Ventura下最稳定的方式:
tell application "System Settings" activate open URL "x-apple.systempreferences:com.apple.preference.sound" end tell
其中com.apple.preference.sound对应声音设置面板,替换为其他标识即可打开对应面板(比如显示器是com.apple.preference.displays,网络是com.apple.preference.network)。
跨版本兼容代码(支持Ventura及更早系统)
如果脚本需要在多个macOS版本运行,可通过系统版本判断切换逻辑:
set osVersion to system version of (system info) if osVersion starts with "13" then tell application "System Settings" activate open URL "x-apple.systempreferences:com.apple.preference.sound" end tell else tell application "System Preferences" activate set current pane to pane "com.apple.preference.sound" end tell end if
定位到子面板
若需直接打开设置面板的子选项(比如声音设置的「输入」标签),可在URL后添加子面板参数:
tell application "System Settings" activate open URL "x-apple.systempreferences:com.apple.preference.sound?Input" end tell
内容的提问来源于stack exchange,提问作者Alwin
相关产品推荐
相关产品推荐

