Search code examples
pythonapplescriptapple-m1macos-ventura

Enabling voice control in AppleScript Ventura


I am trying to use AppleScript to press the switch for activating voice control in macOS Ventura.

The first switch in this image where it toggles voice control:

the first switch in this image where it toggles voice control

I tried the following apple script:

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

Now it does open up the voice control page as shown in the image above. However, it never presses the switch.

I am running this AppleScript in pycharm python with the applescript module (I don't think it really affects the situation much).


Solution

  • For Ventura, the reference to the Voice Control switch is:

    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"
    

    For Sonoma, use:

    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"