Getting the Current Sound Output with AppleScript
I've seen scripts to toggle the sound output, but I'm having trouble customizing it.
Below is what I'm trying, and it's not working. Clearly I'm having trouble getting the name current sound source into a variable so the script can decide accordingly. What am I missing?
Thank you!
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
activate
tell application "System Events"
tell process "System Preferences"
set currentSource to (text field 1 of the selected row of table 1 of scroll area 1 of tab group 1 of window "sound")
if currentSource is "FastTrack Pro"
select (row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is "SAMSUNG")
else if currentSource is "SAMSUNG" then
select (row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is "FastTrack Pro")
end if
end tell
end tell
#quit
end tell
iMac (27-inch, Late 2012), OS X Mountain Lion