Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

theorist9

macrumors 68040
Original poster
May 28, 2015
3,904
3,070
Voice Control is accessed through System Preferences → Accessibility → Voice Control → Enable Voice Control.

As that's a lot of steps, I created a macro for that using KeyBoard Maestro, so it's now activated/inactivated using CTRL-V.

But there's two problems:

1) Depending on what else is running, my system's response to each of those steps can occasionally be slow, so I had to build in sufficient pauses between each step to accommodate the slowest system response. Consequently the macro takes >4 seconds to run.

2) The macro's last step is to click into the Enable Voice Control checkbox, and that can sometimes fail, requiring I monitor it as it's running to ensure it actually completes.

This makes using the macro somewhat tedious. Thus it would be really nice if I there were some way to set a system shortcut for it, as those run nearly instantly, and essentially never fail. I checked under Keyboard → Shortcuts → Accessibility, and wasn't able to find anything. That surprises me, since anyone who needs Voice Control for accessibility reasons probably would not want to have to go through the series of keyboard and mouse actions needed to activate it. So I'm thinking that surely there is some way to expand the MacOS shortcuts to include it....but maybe not.
1692292268865.png
 
Last edited:
Ok, thanks to the feedback of @theorist9, here's the updated, more robust AppleScript that has no fixed delay for clicking the checkbox but tries up to 4 seconds to detect it:

AppleScript:
set theTimeoutInSeconds to 4
tell application "System Preferences"
    -- This opens "Voice Control" of the "Accessibility" preference pane
    reveal anchor "Dictation" of pane id "com.apple.preference.universalaccess"
    activate
end tell
set theTimeout to theTimeoutInSeconds * 10
tell application "System Events" to tell process "System Preferences"
    set i to 1
    -- This waits up to n seconds for the checkbox "Enable Voice Control" to appear (n = theTimeoutInSeconds)
    repeat until i is greater than theTimeout or (exists checkbox "Enable Voice Control" of group 1 of window "Accessibility")
        set i to i + 1
        delay 0.1
    end repeat
    -- This clicks the checkbox "Enable Voice Control"
    click checkbox "Enable Voice Control" of group 1 of window "Accessibility"
end tell
delay 0.5
tell application "System Preferences" to quit

To only click the checkbox if it is not already ticked, replace:
AppleScript:
click checkbox "Enable Voice Control" of group 1 of window "Accessibility"
by
AppleScript:
tell group 1 of window "Accessibility"
    tell checkbox "Enable Voice Control" to if value is 0 then click
end tell

And thanks for @theorist9 for finding the command to list all "anchor" names of the currently opened/active preference pane:
AppleScript:
tell application "System Preferences" to get the name of every anchor in the current pane

And specifically for the "Accessibility" preference pane:
AppleScript:
tell application "System Preferences" to get the name of every anchor in pane id "com.apple.preference.universalaccess"


BTW, to get the labels/identifiers of items, buttons, check boxes etc. you can record your clicks in Automator and edit it as AppleScript.

AppleScript:
tell application "System Preferences"
    reveal anchor "Dictation" of pane id "com.apple.preference.universalaccess"
    activate
end tell
delay 0.5
tell application "System Events" to tell process "System Preferences"
    click checkbox "Enable Voice Control" of group 1 of window "Accessibility"
end tell
delay 0.5
tell application "System Preferences" to quit
 
Last edited:
  • Love
Reactions: theorist9
@arw Just PM'd you b/c it was stopping at the last step, but I fixed that by increasing the first delay to 1.0 s.

It's a nice improvement over my KBM macro, so thanks!

Interestingly, even though it uses Apple Script, it's still not as fast as a system shortcut. Compare, for instance, "Invert Colors", whose activation checkbox is located in a similar place within Accessibility. There's a built-in system shorcut for that, and it's essentially instantaneous. I guess the system shorcuts operate at a lower level.
 
Last edited:
  • Like
Reactions: arw
Glad to hear you got it working!
The fastest way (besides a system shortcut) would be changing the plist entry directly but most HID/Accessibility settings require actually clicking the GUI for the system to register the change.
It would be nice to find the command to force a "settings refresh" after modifying a plist entry. Similar to the built-in system shortcuts functionality.
 
Is anthing here useful? It talks about writing macros to update the plist file, though not about how to force a refresh.

Would that refresh need to be specific to the change, or is it a general refresh? If it's the latter, and that same general refresh occurs when you activate invert colors, then I'm wondering if you could initiate the refresh by just toggling invert colors on and off.
 
Last edited:
With the feedback of @theorist9 I've updated the script in my first post.

Would that refresh need to be specific to the change, or is it a general refresh? If it's the latter, and that same general refresh occurs when you activate invert colors, then I'm wondering if you could initiate the refresh by just toggling invert colors on and off.
I've found out the "refresh" has to be initiated by re-launching the corresponding System LaunchAgent that reads said plist file.
As some checkboxes modify multiple plist-files at once, this would result in also finding all corresponding LaunchAgents to reload them.
Especially in regard to different versions of macOS, I think the AppleScript solution is more robust and easier to update.
 
I presume this discussion is about macOS Big Sur and below, as in Monterey and above there is “Turn Voice Control On/Off” in the Shortcuts app.
VoiceControl.jpg

Regarding editing plists, Voice Control is considered an input method and its use written into ~/Library/Preferences/com.apple.HIToolbox.plist

It could be added with PlistBuddy
Code:
/usr/libexec/PlistBuddy -c "Add :AppleEnabledInputSources:2:'Bundle ID' string com.apple.inputmethod.ironwood" ~/Library/Preferences/com.apple.HIToolbox.plist

/usr/libexec/PlistBuddy -c "Add :AppleEnabledInputSources:2:InputSourceKind string 'Non Keyboard Input Method'" ~/Library/Preferences/com.apple.HIToolbox.plist

but you would still have to start /System/Library/Input Methods/DictationIM.app with the correct command for voice control. Double-clicking or starting it from Terminal ends with “Dictation could not toggle keep alive”
 
  • Like
  • Love
Reactions: theorist9 and arw
I presume this discussion is about macOS Big Sur and below, as in Monterey and above there is “Turn Voice Control On/Off” in the Shortcuts app.
View attachment 2248204

Regarding editing plists, Voice Control is considered an input method and its use written into ~/Library/Preferences/com.apple.HIToolbox.plist

It could be added with PlistBuddy
Code:
/usr/libexec/PlistBuddy -c "Add :AppleEnabledInputSources:2:'Bundle ID' string com.apple.inputmethod.ironwood" ~/Library/Preferences/com.apple.HIToolbox.plist

/usr/libexec/PlistBuddy -c "Add :AppleEnabledInputSources:2:InputSourceKind string 'Non Keyboard Input Method'" ~/Library/Preferences/com.apple.HIToolbox.plist

but you would still have to start /System/Library/Input Methods/DictationIM.app with the correct command for voice control. Double-clicking or starting it from Terminal ends with “Dictation could not toggle keep alive”
Hunh! No, it actually is about Monterey, but I didn't even know there was a Shortcuts app! Probably because I came from High Sierra. Thanks!
 
Last edited:
1) In the case of Mac, yes, no, sometimes, kinda. Need to set it up correctly.

On the Mac side of things, can setup a Shortcut to be a Service, aka [app] > Services > Shortcut-here

services.png

Can place Shortcuts in the menu bar. Can define a key shortcut to run. All defined under info tab from a Shortcut edit screen.

info.png
edit.png


Can even run from command line:

Code:
/usr/bin/shortcuts run "Shortcuts Backup Deltas"

And of course, can open the Shortcuts program and run from there.

On iOS, there is a subcomponent of Shortcuts, Automations. Can define when things run: by time/date, when connecting to Bluetooth, arrive/leave a location, etc.


2) Pretty straight forward: Shortcut requires input or can run without any input. For example, if you have a Shortcut to modify an image, the Shortcut probably would need to get passed to it the image you want to modify.

The input option has a filter where you can narrow down what type of input (eg. per image example, only select images). And when expecting input, can specify what to do when none provided (prompt for it, error out, just run anyway).

If not needing input, should probably be "none" so that no unexpected snags happen when run and no input provided.
 
Last edited:
1) In the case of Mac, yes, no, sometimes, kinda. Need to set it up correctly.

On the Mac side of things, can setup a Shortcut to be a Service, aka [app] > Services > Shortcut-here

View attachment 2248386

Can place Shortcuts in the menu bar. Can define a key shortcut to run. All defined under info tab from a Shortcut edit screen.

info.png
edit.png
Thanks. My Toggle Voice Control shortcut was set up as a Service in Finder, which is always open, yet it didn't run when Shortcuts was closed. However, pinning it to the menu bar worked; it seems you need to do that to have it always be available regardless of whether the Shortcuts app is open. But that's still limited: You need to first open the app to have that pin appear. So I still haven't figured out a way to get it working without opening Shortcuts.

1692551981959.png


Also, the shortcut is giving me this error when I try using it in Excel, which is curious, since Voice Control does work in Excel.

1692552879857.png



I changed Any to No, but that doesn't help:

1692551968322.png
 
Last edited:
My Toggle Voice Control shortcut was set up as a Service in Finder, which is always open, yet it didn't run when Shortcuts was closed. However, pinning it to the menu bar worked; it seems you need to do that to have it always be available regardless of whether the Shortcuts app is open.

Something is not setup correctly for the Shortcut, because I NEVER have the Shortcuts program open/running and all my Shortcuts run, no matter where they are executed from.

Now, "Finder" and "Services" are two different things in the Mac setup screen. "Finder" means the three-dot-circle icon at the top of a Finder window.

The other stuff, again, looks like the keyboard shortcut you setup overlaps with other apps, so when in an MS app, tries doing a Visual Basic thing. That is not a Shortcuts/MacOS error message. I do not use MS apps, so, not even a guess to what's going on with that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.