3

Is there a keyboard shortcut to toggle Voice Control on and off on a Mac running Big Sur? Not Dictation, mind you... Voice Control (under System Preferences > Accessibility > Voice Control).

voice control

I've looked in the Accessibility section of the Keyboard Shortcuts preference pane. Ain't nothing there. It's also (inexplicably) not an option in Accessibility Shortcuts either.

I use Voice Control regularly but not consistently, so I tend to keep it disabled until I need it. It's a hassle to dive into System Preferences every time I want to enable it.

Before you ask, the reason that I don't keep it on all the time (but asleep) is that the floating microphone window is always in the way of something on my MacBook's screen.

I've Googled and Googled and Googled for this. Nada. I have minimal interest in writing an AppleScript/Automator thing to do this... too fragile and finicky for me... but I'm open to all suggestions.

1 Answer 1

1

The example AppleScript code, shown below, was tested in Script Editor under macOS Big Sur with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.

  • 1 Assumes necessary and appropriate settings in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.
  • Assumes that the target checkbox has once before been manually toggled to deal with the permission dialog that appears the first time the target checkbox has been manually toggled.

The example AppleScript code can be use in a Run AppleScript action in an Automator Service/Quick Action that has been assigned a keyboard shortcut in System Preferences > Keyboard > Shortcuts > Services, however, it's been my experience that it is better to use any of the third-party applications that are capable of running AppleScript code and assigning a global keyboard shortcut.

  • As an example, I use FastScripts for some tasks, as well as Hammerspoon for other tasks. (I am not associate with the developers of these products, just a satisfied user.)


Example AppleScript code:

--  # Check to see if System Preferences is 
--  # running and if yes, then close it.
--  # 
--  # This is done so the script will not fail 
--  # if it is running and a modal sheet is 
--  # showing, hence the use of 'killall' 
--  # as 'quit' fails when done so, if it is.
--  #
--  # This is also done to allow default behaviors
--  # to be predictable from a clean occurrence.

if running of application "System Preferences" then
    try
        tell application "System Preferences" to quit
    on error
        do shell script "killall 'System Preferences'"
    end try
    delay 0.1
end if

--  # Make sure System Preferences is not running before
--  # opening it again. Otherwise there can be an issue
--  # when trying to reopen it while it's actually closing.

repeat while running of application "System Preferences" is true
    delay 0.1
end repeat

--  # Open System Preferences to the Accessibility pane. 

tell application "System Preferences" to ¬
    reveal pane id "com.apple.preference.universalaccess"


tell application "System Events"
    tell application process "System Preferences"
        tell window 1
            
            --  # Wait for the target UI element to be available.
            
            set i to 0
            repeat until exists scroll area 1
                delay 0.1
                set i to i + 1
                if i ≥ 30 then return
            end repeat
            
            --  # Select Voice Control.
            
            try
                select (rows of table 1 of scroll area 1 ¬
                    whose value of static text 1 of ¬
                    UI element 1 is "Voice Control")
            end try
            
            --  # Wait for the target UI element to be available.
            
            set i to 0
            repeat until exists checkbox 3 of group 1
                delay 0.1
                set i to i + 1
                if i ≥ 30 then return
            end repeat
            
            --  # Click checkbox Enable Voice Control.
            
            click checkbox 3 of group 1
            
        end tell
    end tell
end tell

delay 0.2

tell application "System Preferences" to quit

Notes:

The example AppleScript code uses UI Scripting, which can be kludgy at times, and assuming System Preferences is normally already closed the script will cause the System Preferences icon to bounce one time it the Dock.



Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

3
  • 1
    This works! While I'm not thrilled about using an AppleScript that relies on UI elements (What happens when Apple changes the System Prefs interface?), it's a good solution while it works. Anyway, I simply copied and pasted this script into a Better Touch Tool action and it worked first try. Amazing. Many thanks. Thanks also for commenting your code. That's helpful too.
    – Sam
    Jul 5, 2021 at 20:15
  • @Sam, RE: "(What happens when Apple changes the System Prefs interface?)" -- Then as the usual protocol goes, the code will need to be adjusted to work with that version of macOS. It's really not a big deal and if you need help modifying it, then ask a question and I'm sure it will get answered. Jul 5, 2021 at 20:31
  • Ok. Fair enough.
    – Sam
    Jul 6, 2021 at 0:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .