Skip to content

Instantly share code, notes, and snippets.

@codeanpeace
Created January 2, 2019 00:09
Show Gist options
  • Save codeanpeace/15dbefaf027136392dd50146959bb9a2 to your computer and use it in GitHub Desktop.
Save codeanpeace/15dbefaf027136392dd50146959bb9a2 to your computer and use it in GitHub Desktop.
AppleScript that switches audio, toggling between display and AMP / DAC
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.sound"
end tell
tell application "System Events"
tell application process "System Preferences"
tell tab group 1 of window "Sound"
delay 1
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 "Display Audio"
else
set selected of row 4 of table 1 of scroll area 1 to true
set deviceselected to "FiiO USB DAC-E10"
end if
end tell
end tell
end tell
tell application "System Preferences"
quit
end tell
tell application "Growl"
set the allNotificationsList to {"Sound Notification"}
set the enabledNotificationsList to {"Sound Notification"}
register as application "Toggle Sound Output" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Script Editor"
notify with name "Sound Notification" title "Audio Output" description deviceselected application name "Toggle Sound Output"
end tell
@codeanpeace
Copy link
Author

codeanpeace commented Jan 2, 2019

See alternative command-line utility switchaudio-osx:
$ brew install switchaudio-osx

$ switchaudiosource -s "FiiO USB DAC-E10"
$ switchaudiosource -s "Display Audio"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment