Toggling between two sound outputs

In OS X 10.4.8, this works for me:


tell application "System Preferences" to reveal anchor "output" of pane id "com.apple.preference.sound"
tell application "System Events" to tell (table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences")
	set S to selected of rows
	if item 1 of S is false then
		select row 1
	else
		select row 2
	end if
end tell
tell application "System Preferences" to quit

If you have more than two sound output devices this selects the next one in the list:

tell application "System Preferences" to reveal anchor "output" of pane id "com.apple.preference.sound"
tell application "System Events" to tell (table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences")
	set S to selected of rows
	repeat with C from 1 to (count of S)
		if (item C of S) is true then exit repeat
	end repeat
	select row (C mod (count of S) + 1)
end tell
tell application "System Preferences" to quit

John M