In a previous post, I discussed using FastScripts in combination with a simple AppleScript to assign a hot-key to accomplish annoying tasks.
I frequently change my sound output to the TV I have in my other room, and back again to my main office. It gets annoying to have to use the mouse, so using FastScripts and a modified AppleScript I found online, I toggle between audio sources.
This script currently only works with toggling between two outputs: "Line Out" and "Digital Out", but is easily made to toggle between any number of outputs. To add more/different outputs to switch between, simply add to the "theOutputs" list at the top by putting the name of the output in quotes, and separated by a comma. Please note that the outputs you wish to toggle between must be written EXACTLY as they are in your Sound Preference Pane (read: Case Sensitive!), but can be in any order you choose:

Code:
set theOutputs to {"Digital Out", "Line Out"}
tell application "System Events"
set frontmostapp to item 1 of (get name of processes whose frontmost is true)
end tell
tell application "System Preferences" to activate
tell application "System Events"
get properties
tell process "System Preferences"
if (menu item "Sound" of menu "Window" of menu bar 1) exists then
else
click menu item "Sound" of menu "View" of menu bar 1
delay 1
end if
set theRows to every row of table 1 of scroll area 1 of ¬
tab group 1 of window "sound"
click radio button "Output" of tab group 1 of window "Sound"
set nextOutput to ""
set nextIndex to 0
(* Obtain Selected Output / Choose Next Output based on Selected*)
repeat with aRow in theRows
if selected of aRow is true then
set currentlySelectedOutput to (value of text field 1 of aRow as text)
if currentlySelectedOutput is in theOutputs then
set selectedIndex to my getitemindex(theOutputs, currentlySelectedOutput)
if (count of theOutputs) is equal to selectedIndex then
set nextIndex to 1
else
set nextIndex to (selectedIndex + 1)
end if
else
set nextIndex to 1
end if
set nextOutput to (get item nextIndex of theOutputs)
exit repeat
end if
end repeat
(* Select the chosen Output *)
repeat with aRow in theRows
if (value of text field 1 of aRow as text) ¬
is equal to nextOutput then
set selected of aRow to true
exit repeat
end if
end repeat
end tell
end tell
# tell application "System Preferences" to quit
tell application frontmostapp to activate
on getitemindex(this_list, this_item)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end getitemindex