Sound-switching script stopped working in Maverick

Hi all!

I am trying to figure out why my script for switching the sound input source has stopped working in Maverick. It worked great before, but now it will first return an error about not finding the menu item, but if I run the script again right after it works as intended. Any ideas?

# Script to externalize the sound to the TV instead of the computer.
# Written by Daniel Henriksson, May 2011. Based on various internet hints, primarily the following page by Miraglia: http://hints.macworld.com/article.php?story=20050614171126634 

tell application "System Preferences" to activate
tell application "System Events"
	get properties
	#Change the Sound preferences to use the TV (called "32LG2000")
	tell process "System Preferences"
		click menu item "Sound" of menu "View" of menu bar 1
		set theRows to every row of table 1 of scroll area 1 of ¬
			tab group 1 of window "sound"
		set theOutputs to {} as list
		repeat with aRow in theRows
			if (value of text field 1 of aRow as text) ¬
				is equal to "32LG2000" then
				set selected of aRow to true
				exit repeat
			end if
		end repeat
	end tell
end tell
tell application "System Preferences" to quit

Thankful for help!

Hi,

try this, it uses terminology of System Preferences to open the proper pane


tell application "System Preferences"
	activate
	reveal anchor "output" of pane id "com.apple.preference.sound"
end tell


tell application "System Events"
	tell process "System Preferences"
		try
			tell (1st row of table 1 of scroll area 1 of ¬
				tab group 1 of window "sound" whose value of text field 1 is "32LG2000")
				set selected to true
			end tell
		end try
	end tell
end tell

quit application "System Preferences"


Hi Stefan,

thanks for the quick reply, will try it out as soon as I get home. Your version is a lot leaner than mine, thanks for the general improvements :slight_smile:

Hi again,

thanks for the help, the script works just fine and is also faster than my initial version :smiley: