Applescript or other Technique Enable/Disable Voice Control on Catalina

I recently installed Catalina and I am very impressed with the potential for Voice Control to automate various parts of my work.

However, I am disappointed in the degree to which my 2017 Retina 5K iMac slows down when I activate Voice Control - and I am surprised I have not read more about others with similar experiences. Maybe this is because I use multiple monitors and multiple spaces? Just swiping between spaces slows down very notably when Voice Control is turned on.

I may wind up upgrading this computer - which will raise the question of whether I should get a newer iMac vs. an iMac Pro vs the new Mac Pro. For now it would be helpful to have a Macro so I can quickly turn Voice Control on/off at will.

The checkbox under System Preferences does not have an obvious way to automate it in KM. Do I need to step through the menus and then use Find Image to identify the checkbox? Or is there a way via Applescript to enable/disable voice control? Other suggestions?

I made some progress using UI Browser

I believe this is very close - but the line to "select static text" and thus select the Voice Control option is not working - the script cancels at that point.

Ideas?

activate application
 "System Preferences"
tell application "System Events"
tell process "System Preferences"
click button "Accessibility"  of scroll area 1 of window "System Preferences" 
select static text "Voice Control"  of UI element 1 of row 13 of table 1 of scroll area 1 of window "Accessibility" 
click checkbox "Enable Voice Control"  of group 1 of window "Accessibility" 
end tell
end tell

Well this Macro works - but it is not elegant and has a delay in it so the keystrokes work.

Any improved ideas for this?

Thank you for sharing. I use voice control mainly for dictation and a keyboard shortcut to enable/disable Is needed
I have found that

  • you could leave open the preference pane with voice control in the background
  • simply use the Applescript as in your post to check the box as a KM macro with a hotkey assigned
  • with a hotkey to trigger the macro, dictation can be turned on and off with ease(a 2 second delay), the preference pane does not even come to the foreground

This works quite well.Thank you for sharing

1 Like

Not sure if this will help, but this will at least open System Preferences at Voice Control.

tell application "System Preferences"
	reveal anchor "Dictation" of pane id "com.apple.preference.universalaccess"
	activate
end tell

You'd still need to use the UI scripting part to toggle the checkbox though.

 

[EDIT]

I added the UI scripting part:

tell application "System Preferences"
	reveal anchor "Dictation" of pane id "com.apple.preference.universalaccess"
	-- activate
end tell

delay 0.5
tell application "System Events"
	tell process "System Preferences"
		click checkbox "Enable Voice Control" of group 1 of window "Accessibility"
	end tell
end tell

tell application "System Preferences" to quit

This works for me, but you'll probably need to tweak the delays for your machine.

[/EDIT]

2 Likes

Excellent - much appreciated

Can I ask where you found the info to write this?

I have a script that grabs the ID of the current pane open in System Preferences, copies it to the clipboard, and also shows the name of all the panes contained within it.

 

tell application "System Preferences"
	
	set currentPane to get current pane
	set paneID to id of currentPane
	
	set the clipboard to paneID as text
	display dialog quoted form of paneID & " copied to clipboard"
	
	-- Get names of every pane contained within the preference pane
	set the result to get the name of every anchor of pane id paneID
	set paneNames to the result
	
end tell

That's very helpful - big thanks

This is fantastic--thank you!

@peternlewis I would still love to have native Keyboard Maestro support for toggling voice control. This is especially the case because it turns out that if the cursor is in a text field like this one (within Chrome), the voice control "type" command does not work. So if I want to dictate, I have to turn OFF voice control, and then turn ON dictation [and of course turn back on voice control] :crazy_face:

1 Like

This is fantastic!
Thank you

How would you make it specifically turn off or on?

EDIT: solved. I had the system check to see if Dictation is running – doesn't work, though if you also want to be dictating

if application "DictationIM" is not running then

tell application "System Preferences"
	reveal anchor "Dictation" of pane id "com.apple.preference.universalaccess"
	-- activate
end tell

delay 0.5
tell application "System Events"
	tell process "System Preferences"
		click checkbox "Enable Voice Control" of group 1 of window "Accessibility"
	end tell
end tell

tell application "System Preferences" to quit
end if

Jono, that was PHENOMENAL! Thanks so much, Andrew

Just out of curiosity what keyboard shortcut combo are you guys using to trigger this?

Hyperkey + Home

Thanks for reminding me of Voice Control on macOS Catalina. Seems to work really great. (I have to get used to using it though…)