Accessibility Sonoma System Settings

Hello!

Recently upgraded from Big Sur to Sonoma out of necessity for no longer supported work apps. The system settings has royally screwed up my accssibility scripts. Only have the use of one hand and am ridiculously disabled, thes escripts help me a tonne and would be a shame to use. Was wondering if I could get some help getting them working again?

Toggle voice control on and off

set outputA to 1 --change this to the actual 'line number' of your first desired output
set outputB to 2 --change this to the actual 'line number' of your second desired output

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.universalaccess"
	try
		set miniaturized of windows to false -- most apps
	end try
end tell

delay 0.5

tell application "System Events"
	tell window 1 of application process "System Preferences"
		select row 12 of table 1 of scroll area 1
		delay 0.5
		click checkbox "Enable Voice Control" of group 1
	end tell
end tell

Toggle sound device between two devices

set outputA to 1 --change this to the actual 'line number' of your first desired output
set outputB to 2 --change this to the actual 'line number' of your second desired output

tell application "System Settings"
	activate
	set current pane to pane "com.apple.preference.sound"
	set miniaturized of windows to false -- most apps
	end try
end tell


tell application "System Events"
	tell application process "System Preferences"
		repeat until exists tab group 1 of window "Sound"
		end repeat
		tell tab group 1 of window "Sound"
			click radio button "Output"
			if (selected of row outputA of table 1 of scroll area 1) then
				set selected of row outputB of table 1 of scroll area 1 to true
			else
				set selected of row outputA of table 1 of scroll area 1 to true
			end if
		end tell
	end tell
end tell

Any help would be appreciated, thank you

This will toggle VC in Sequoia:

activate application “System Settings”
tell application “System Events”
tell process “System Settings”
click checkbox “Voice Control” of group 1 of scroll area 1 of group 1 of list 2 of splitter group 1 of list 1 of window “Voice Control”
end tell
end tell

This will change your output setting.

Sound_Output_Switch(2)

on Sound_Output_Switch(theDesiredRow)
	do shell script "open x-apple.systempreferences:com.apple.Sound-Settings.extension"
	tell application "System Events"
		tell application process "System Settings"
			tell window 1
				--Confirm the panel is open and populated.
				repeat until group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 exists
					delay 0
				end repeat
				--press Output radio button
				perform action "AXPress" of radio button 1 of UI element 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
				set selected of row theDesiredRow of UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 to true
			end tell
		end tell
	end tell
end Sound_Output_Switch

Seriously ?!

(* smh *)

It’s an older code block sir, but it checks out.

There was a time when you couldn’t just ask System Settings to open. I offered some functional code I had lying around to someone who asked. I was a little busy with a paying job so they get what I have at hand.

The annoying thing here is that there were two paragraphs that followed after “seriously?!” which I hadn’t realised failed to post: a paragraph basically bitching about do shell script, and a code block with code to reveal the appropriate settings pane. I guess you weren’t the only one who incurred the cost of trying to post in a rush.

About System Settings not opening previously, was it an actual failure for the app to launch with AppleScript at all ? If this was the case, I should think the command line invocation of open would also fail, as I was under the impression that they both perfor the same system call. Could it have been that the main settings window didn’t appear on the screen when one would normally have expected it to ?

So, a feature of the System Settings app carried over from the previous System Preferences is that it is one of a very short list of apps that can have its UI scripted without the need for its UI to be visible. This is visually less jarring obviously, but the greatest benefit is that, in not needing the UI to be on screen, it can receive simulated mouse clicks and keystrokes from System Events without interrupting whatever the user is doing with the mouse or keyboard at the time.

But, perhaps I’m misremembering the common underpinnings of the AppleScript and command-line open command calls. If they’re, in fact, totally different, then Apple would definitely have bollocks’d up the scriptability of the settings app during transition from its previous incarnation, which is infamously did when iTunes became Music.

Hi ruddety,

Nice to meet you!

I’m not very good at English, and I also really struggle with handling System Events, so I might be misunderstanding your intention. However, I thought the method I use might be helpful, so I wanted to share it with you.

Please keep in mind that I’m using OS 15, so it might be different from Sonoma.

Toggle voice control on and off

tell application id "com.apple.systempreferences"
	activate
	set miniaturized of the settings window to false
end tell

#wait systempreferences
repeat 10 times
	tell application id "com.apple.systempreferences"
		set boolFrontMost to frontmost as boolean
	end tell
	if boolFrontMost is true then
		# one-second prayer after exit
		delay 1
		exit repeat
	else
		tell application id "com.apple.systempreferences" to activate
		delay 0.5
	end if
end repeat

#set anchor
tell application id "com.apple.systempreferences"
	reveal anchor "AX_VOICE_CONTROL_ENABLED" of pane id "com.apple.Accessibility-Settings.extension"
end tell
tell application id "com.apple.systempreferences" to activate

#wait Accessibility
repeat 10 times
	tell application id "com.apple.systempreferences"
		activate
		tell current pane
			set strPaneID to id
		end tell
	end tell
	if strPaneID is "com.apple.systempreferences.GeneralSettings" then
		delay 0.5
	else if strPaneID is "pane com.apple.Accessibility-Settings.extension" then
		exit repeat
	end if
end repeat

#wait Voice Control
repeat 10 times
	tell application id "com.apple.systempreferences"
		tell front window
			set strWindowName to name
		end tell
	end tell
	if strWindowName is "Voice Control" then
		exit repeat
	else
		delay 0.5
	end if
end repeat

# system events
tell application id "com.apple.systempreferences"
	activate
	tell application "System Events"
		tell process "System Settings"
			(*
OS15 note
Voice Control  Off time target
group 2 of splitter group 1 of group 1 of window "Voice Control"
Voice Control  On time target
list 2 of splitter group 1 of list 1 of window "Voice Control"
		*)
			try
				# OFF to ON
				select checkbox 1 of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Voice Control"
				click checkbox 1 of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Voice Control"
			on error
				#ON to OFF
				select checkbox 1 of group 1 of scroll area 1 of group 1 of list 2 of splitter group 1 of list 1 of window "Voice Control"
				click checkbox 1 of group 1 of scroll area 1 of group 1 of list 2 of splitter group 1 of list 1 of window "Voice Control"
			end try
			
		end tell
	end tell
end tell

Toggle sound device between two devices


tell application id "com.apple.systempreferences"
	activate
	set miniaturized of the settings window to false
end tell

#wait systempreferences
repeat 10 times
	tell application id "com.apple.systempreferences"
		set boolFrontMost to frontmost as boolean
	end tell
	if boolFrontMost is true then
		# one-second prayer after exit
		delay 1
		exit repeat
	else
		tell application id "com.apple.systempreferences" to activate
		delay 0.5
	end if
end repeat

#set anchor
tell application id "com.apple.systempreferences"
	reveal anchor "output" of pane id "com.apple.Sound-Settings.extension"
end tell
tell application id "com.apple.systempreferences" to activate

#wait Sound-Settings
repeat 10 times
	tell application id "com.apple.systempreferences"
		activate
		tell current pane
			set strPaneID to id
		end tell
	end tell
	if strPaneID is "com.apple.systempreferences.GeneralSettings" then
		delay 0.5
	else if strPaneID is "com.apple.Sound-Settings.extension" then
		exit repeat
	end if
end repeat

#wait Sound
repeat 10 times
	tell application id "com.apple.systempreferences"
		tell front window
			set strWindowName to name
		end tell
	end tell
	if strWindowName is "Sound" then
		exit repeat
	else
		delay 0.5
	end if
end repeat
(*
MacOS15 NOTE
# Voice Control ON  Time target
list 2 of splitter group 1 of list 1 of window "Sound"

# Voice Control OFF  Time target
group 2 of splitter group 1 of group 1 of window "Sound"

*)
# system events
tell application id "com.apple.systempreferences"
	activate
	tell application "System Events"
		tell process "System Settings"
			#TYPE A
			try
				tell outline 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of list 2 of splitter group 1 of list 1 of window "Sound"
					repeat with itemNo from 1 to 2 by 1
						tell row itemNo
							set recordProperties to properties
							set boolSelect to selected of recordProperties
							if boolSelect is false then
								select
								exit repeat
							end if
						end tell
					end repeat
					log "Done type A"
				end tell
			on error
				#TYPE B 
				tell outline 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Sound"
					repeat with itemNo from 1 to 2 by 1
						tell row itemNo
							set recordProperties to properties
							set boolSelect to selected of recordProperties
							if boolSelect is false then
								select
								exit repeat
							end if
						end tell
					end repeat
					log "Done type B"
				end tell
			end try
		end tell
		# click
	end tell
end tell

Hope this helps!

Three sound output handlers.

Sound_Output_Current() -->"Display Audio"
set theDesiredAudioSourceName to item 2 of Sound_Output_Options() -->"iMac Speakers"
Sound_Output_Select_By_Name(theDesiredAudioSourceName)
Sound_Output_Current() -->"iMac Speakers"


on Sound_Output_Select_By_Name(theDesiredAudioSourceName)
	tell application "System Settings"
		activate
		reveal pane "Sound"
	end tell
	tell application "System Events"
		tell application process "System Settings"
			tell window 1
				repeat until group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 exists --Confirm the Sound panel is open and populated.
					delay 0
				end repeat
				perform action "AXPress" of radio button 1 of UI element 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 --Press Output tab radio button
				repeat until UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 exists
					delay 0
				end repeat
				set rowList to rows of UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
				repeat with i from 1 to length of rowList
					set thisAudioSourceName to name of (item 3 of (get entire contents of (item i of rowList)))
					if thisAudioSourceName is theDesiredAudioSourceName then
						set selected of row i of UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 to true
						exit repeat
					end if
				end repeat
			end tell
		end tell
	end tell
	return theDesiredAudioSourceName
end Sound_Output_Select_By_Name

on Sound_Output_Current()
	tell application "System Settings"
		activate
		reveal pane "Sound"
	end tell
	tell application "System Events"
		tell application process "System Settings"
			tell window 1
				repeat until group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 exists --Confirm the Sound panel is open and populated.
					delay 0
				end repeat
				perform action "AXPress" of radio button 1 of UI element 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 --Press Output tab radio button
				repeat until UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 exists
					delay 0
				end repeat
				set rowList to rows of UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
				repeat with i from 1 to length of rowList
					set thisRow to item i of rowList
					selected of thisRow
					if (selected of thisRow) then
						set thisAudioSourceName to name of (item 3 of (get entire contents of (item i of rowList)))
						return thisAudioSourceName
					end if
				end repeat
			end tell
		end tell
	end tell
end Sound_Output_Current

on Sound_Output_Options()
	tell application "System Settings"
		activate
		reveal pane "Sound"
	end tell
	tell application "System Events"
		tell application process "System Settings"
			tell window 1
				repeat until group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 exists --Confirm the Sound panel is open and populated.
					delay 0
				end repeat
				perform action "AXPress" of radio button 1 of UI element 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 --Press Output tab radio button
				repeat until UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 exists
					delay 0
				end repeat
				set rowList to rows of UI element 1 of scroll area 1 of group 2 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1
				set AudioOutputOptions to {}
				repeat with i from 1 to length of rowList
					set thisRow to item i of rowList
					set thisAudioSourceName to name of (item 3 of (get entire contents of (item i of rowList)))
					set the end of AudioOutputOptions to thisAudioSourceName
				end repeat
			end tell
		end tell
	end tell
	return AudioOutputOptions
end Sound_Output_Options
1 Like