I am now revisiting this for MacOS Ventura.
My current script does not after the upgrade. I kind of expected that.
I have issues fixing this myself though, so maybe someone is able to help.
This is my current script and below is the debug log.
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events" to tell process "System Preferences"
tell tab group 1 of window "Sound"
click radio button "Output"
if (selected of row 4 of table 1 of scroll area 1) then
set selected of row 3 of table 1 of scroll area 1 to true
set deviceselected to "External Headphones"
else
set selected of row 4 of table 1 of scroll area 1 to true
set deviceselected to "Mac Pro Speakers"
end if
end tell
end tell
quit application "System Preferences"
return deviceselected
Debug log:
[09:06:35.425] Toggle Output Device[Hotkey] Processing complete
[09:06:35.425] Toggle Output Device[Hotkey] Passing output '' to Run Script
[09:06:35.564] ERROR: Toggle Output Device[Run Script] 36:104: execution error: System Settings got an error: AppleEvent handler failed. (-10000)
[09:06:35.570] Toggle Output Device[Run Script] Processing complete
[09:06:35.571] Toggle Output Device[Run Script] Passing output '' to Run Script
[09:06:35.571] Toggle Output Device[Run Script] Passing output '' to Post Notification
[09:06:35.697] ERROR: Toggle Output Device[Run Script] 36:104: execution error: System Settings got an error: AppleEvent handler failed. (-10000)
Plus attached is a screenshot of my system settings and alfred workflow