Enabling voice control in AppleScript Ventura
Question:
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:
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).
Answers:
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"
Here is a working script, integrating the above answer.
This version integrates a corrected reference to the Voice Control checkbox, which was provided (above) by Ron Reuter. This works for me under macOS Ventura, as of 2023-01-30.
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 "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" exists
delay 0.1
end repeat
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"
end tell
end tell
tell application "System Settings" to quit
Unfortunately not working any more:
System Events got an error: Script Editor is not allowed assistive access.
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:
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).
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"
Here is a working script, integrating the above answer.
This version integrates a corrected reference to the Voice Control checkbox, which was provided (above) by Ron Reuter. This works for me under macOS Ventura, as of 2023-01-30.
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 "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" exists
delay 0.1
end repeat
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"
end tell
end tell
tell application "System Settings" to quit
Unfortunately not working any more:
System Events got an error: Script Editor is not allowed assistive access.