Created
June 19, 2018 09:04
-
-
Save hmsk/145a5d4277c724d2f98bb8795a7a3ded to your computer and use it in GitHub Desktop.
Toggle output device through System Preferences on macOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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