Applescript 自动机错误(系统事件发生错误:无法获取复选框)

Applescript 自动机错误(系统事件发生错误:无法获取复选框),applescript,automator,macos-mojave,Applescript,Automator,Macos Mojave,我有一个自动程序,可以在单声道和立体声之间切换音频。它过去是有效的,但莫哈韦的更新似乎破坏了它。我已经给了它可访问性许可,但仍然没有运气。有什么问题吗 tell application "System Preferences" launch reveal anchor "Hearing" of pane id "com.apple.preference.universalaccess" tell application "System Events" to tell pr

我有一个自动程序,可以在单声道和立体声之间切换音频。它过去是有效的,但莫哈韦的更新似乎破坏了它。我已经给了它可访问性许可,但仍然没有运气。有什么问题吗

tell application "System Preferences"
    launch
    reveal anchor "Hearing" of pane id "com.apple.preference.universalaccess"
    tell application "System Events" to tell process "System Preferences"
        delay 0.5
        click the checkbox "Play stereo audio as mono" of window "Accessibility"
    end tell
end tell
tell application "System Preferences" to quit
错误消息如下所示:

“运行AppleScript”操作遇到错误:“系统事件已获取” 错误:无法获取窗口的复选框“将立体声音频作为单声道播放” 进程“系统首选项”的“可访问性”


提前谢谢你

试试看

tell application "System Preferences"
    reveal anchor "Hearing" of pane id "com.apple.preference.universalaccess"
end tell
tell application "System Events"
    repeat until exists of checkbox "Play stereo audio as mono" of group 1 of window "Accessibility" of application process "System Preferences"
        delay 0.1
    end repeat
    click checkbox "Play stereo audio as mono" of group 1 of window "Accessibility" of application process "System Preferences"
end tell
tell application "System Preferences" to quit

那很有效,非常感谢!我想知道“第一组”是什么意思?这就是为什么我的代码不起作用的原因吗?@johan456789,添加了第1组的
之所以起作用,是因为苹果改变了macOS Mojave中该窗口的对象布局,而不是以前版本的macOS。请看一看:我希望有一个小技巧是有益的:尽量避免对脚本功能所依赖的任何东西使用
delay
命令。编写UI脚本时,最好(更可靠/健壮)测试元素是否存在,作为脚本继续执行的条件。这可以通过一个短的
repeat
循环来完成,在这个循环中,
delay
命令以非必要的方式使用:作为一个松散的例子,
重复,直到名为“Foo bar”的复选框存在为止
延迟0.5
结束重复