System Preferences. Voice control.

–Hello.

–This works … but it’s very primitive.
–Any more reasonable suggestions?

tell application “System Preferences”
if it is running then
quit
delay 0.5
end if
end tell

tell application “System Preferences”
activate
end tell

tell application “System Events”
tell process “System Preferences”
keystroke “f” using command down
delay 0.3

	keystroke "Control por voz" -- spanish
	delay 0.9 
	keystroke return
	
	
	keystroke "a" using command down 
	delay 0.5 
	keystroke return
            key code 51 using command down 
end tell

end tell

–In advance, thank you very much for any help.

What’s the end goal?

“Control por voz” sounds like it would translate to “Voice Control,” but I get no hits for that searching System Preferences… I don’t even know what System Preferences pane you’re bringing up.

I’ve got this script that I use to quickly change sound settings on my computers. It might be useful as a reference to you for directly bringing up a System Preferences pane and reading and setting values in it.

If you let me know exactly what you’re trying to achieve, perhaps I can be more helpful. Although differences in localization may make it difficult here.

tell application "System Preferences"
	reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events"
	tell process "System Preferences"
		set currentOutput to the first row of table 1 of scroll area 1 of tab group 1 of window "Sound" whose selected is true
		set currentOutputName to the value of text field 1 of currentOutput
	end tell
end tell

if currentOutputName is "Line Out" then
	set currentOutputName to "Computer Soundbar"
else if currentOutputName is "SC-75" then
	set currentOutputName to "Home Theater Receiver"
end if


set soundOptionsList to {"Computer Soundbar", "Home Theater Receiver", "Living Room", "Master Bedroom", "iPhone(s)"}

if currentOutputName is not in soundOptionsList then copy currentOutputName to the beginning of soundOptionsList



set soundChoice to (choose from list soundOptionsList with prompt "Select sound output" default items currentOutputName OK button name {"Go"} cancel button name {"Cancel"}) as text

try
	tell application "System Events"
		tell process "System Preferences"
			if soundChoice is "false" then
				return
			else if soundChoice is "Computer Soundbar" then
				select (row 2 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is "Line Out")
			else if soundChoice is "Home Theater Receiver" then
				select (row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is "SC-75")
			else if soundChoice is "iPhone(s)" then
				tell application "Airfoil.app"
					activate
				end tell
			else
				select (row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is soundChoice)
			end if
		end tell
	end tell
on error
	display dialog "There was a problem selecting \"" & soundChoice & "\" in the Sound Control Panel." buttons {"Cancel"} default button "Cancel"
end try
tell application "System Preferences" to quit