Get the Sound Output Device Name with AppleScript

applescriptaudio

How can I get the current sound output device name with AppleScript?

For example, in my System Preferences: Sound pane "Internal Speakers" is currently selected. All I need to do is retrieve that device name — "Internal Speakers" or "Headphones" or "Bluetooth Speakers" — whichever is currently in use.

(I do not need a switcher/changer to another device.)

Best Answer

SwitchAudioSource http://code.google.com/p/switchaudio-osx/ is a command-line utility which works under Lion and Mtn Lion (I don't know about newer OS X versions). If it works for you, then you can use it in an AppleScript, as follows:

on run

    set theSwitch to "path_to_SwitchAudioSource"
    set theLine to "Current audio output device is:"

    do shell script theSwitch & " -c"
    display dialog theLine & return & return & result buttons {"OK"}

end run