在 AppleScript Ventura 中启用语音控制

问题描述 投票:0回答:2

我正在尝试使用 AppleScript 按下开关以在 macOS Ventura 中激活语音控制。

此图中的第一个开关用于切换语音控制:

the first switch in this image where it toggles voice control

我尝试了以下苹果脚本:

do shell script "open -b com.apple.systempreferences " & ¬
        "/System/Library/PreferencePanes/UniversalAccessPref.prefPane"

    tell application "System Events"
        tell its application process "System Settings"
            repeat until UI element 4 of group 1 of scroll area 1 of group 1 of ¬
                group 2 of splitter group 1 of group 1 of window "Accessibility" exists
                delay 0.1
        end repeat
        click UI element 1 of group 3 of scroll area 1 of group 1 of group 2 ¬
                of splitter group 1 of group 1 of window "Accessibility"
        repeat until checkbox 3 of group 2 of scroll area 1 of group 1 of group ¬
            2 of splitter group 1 of group 1 of window "Voice Control" exists
            delay 0.1
        end repeat
        click button 5 of group 1 of scroll area 1 of window "Voice Control"
        end tell
    end tell

    tell application "System Settings" to quit

现在它确实打开了语音控制页面,如上图所示。然而,它永远不会按下开关。

我正在 pycharm python 中使用 applescript 模块运行此 AppleScript(我认为这对情况影响不大)。

python applescript apple-m1 macos-ventura
2个回答
2
投票

这是一个工作脚本,集成了上述答案。

此版本集成了对语音控制复选框的更正参考,该参考由 Ron Reuter 提供(见上文)。截至 2023 年 1 月 30 日,这对我在 macOS Ventura 下有效。

do shell script "open -b com.apple.systempreferences " & ¬
    "/System/Library/PreferencePanes/UniversalAccessPref.prefPane"

tell application "System Events"
    tell its application process "System Settings"
        repeat until UI element 4 of group 1 of scroll area 1 of group 1 of ¬
            group 2 of splitter group 1 of group 1 of window "Accessibility" exists
            delay 0.1
        end repeat
        click UI element 1 of group 3 of scroll area 1 of group 1 of group 2 ¬
            of splitter group 1 of group 1 of window "Accessibility"
        repeat until checkbox "Voice Control" of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Voice Control" exists
            delay 0.1
        end repeat
        click checkbox "Voice Control" of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Voice Control"
        
    end tell
end tell

tell application "System Settings" to quit

1
投票

对于 Ventura,语音控制开关的参考是:

click checkbox "Voice Control" of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Voice Control"

对于索诺玛,请使用:

click checkbox "Voice Control" of group 1 of scroll area 1 of group 1 of list 2 of splitter group 1 of list 1 of window "Voice Control"
© www.soinside.com 2019 - 2024. All rights reserved.