Skip to content

Instantly share code, notes, and snippets.

@einarlove
Created January 11, 2014 22:04
Show Gist options
  • Save einarlove/8377578 to your computer and use it in GitHub Desktop.
Save einarlove/8377578 to your computer and use it in GitHub Desktop.
This NSApplescript toggles between the Internal Speakers and Apple TV. Could be saved as a service and triggered by keyboard shortcut or as an Alfred workflow
(*
-- Change audio output between two outputs
-- Bind to a keyboard shortcut or an Alfred keyword
--
-- @author Einar Löve <einar@unfold.no>
-- @link http://github.com/einarlove
*)
set defaultOutput to "Internal Speakers"
set alternativeOutput to "Apple TV"
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
tell application "System Events"
tell process "System Preferences"
set outputList to table 1 of scroll area 1 of tab group 1 of window "Sound"
set currentOutput to value of text field of UI element 1 of outputList whose selected = true
set outputName to first item of currentOutput
if outputName is defaultOutput then
set outputName to alternativeOutput
else
set outputName to defaultOutput
end if
select (row 1 of outputList whose value of text field 1 is outputName)
end tell
end tell
quit
end tell
@mittnavnermike
Copy link

Thanks a bunch for this!

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