Skip to content

Instantly share code, notes, and snippets.

@hmsk
Created June 19, 2018 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmsk/145a5d4277c724d2f98bb8795a7a3ded to your computer and use it in GitHub Desktop.
Save hmsk/145a5d4277c724d2f98bb8795a7a3ded to your computer and use it in GitHub Desktop.
Toggle output device through System Preferences on macOS
tell application "System Events"
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
tell application process "System Preferences"
repeat until (exists window "Sound" of application "System Preferences")
delay 1
end repeat
tell tab group 1 of window "Sound"
click radio button "Output"
if (selected of row 2 of table 1 of scroll area 1) then
set selected of row 1 of table 1 of scroll area 1 to true
set deviceselected to "Internal Speakers"
else
set selected of row 2 of table 1 of scroll area 1 to true
set deviceselected to "External Output"
end if
end tell
end tell
tell application "System Preferences" to quit
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment