Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

flash1996

macrumors newbie
Original poster
Oct 27, 2013
3
0
I have this script that only works once the system preferences is open and giving this error. "System Events got an error: Can’t get window \"sound\" of process \"System Preferences\"." number -1728 from window "sound" of process "System Preferences"

here is the script
Code:
tell application "System Preferences" to activate
tell application "System Events"
get properties
tell process "System Preferences"
delay 3
click menu item "Sound" of menu "View" of menu bar 1
delay 2
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
copy (value of text field 1 of aRow as text) to the end of theOutputs
end repeat
tell application "Finder"
activate
set desiredOutput to display dialog ¬
"Choose Sound Output: " buttons theOutputs default button "Headphones"
end tell
repeat with aRow in theRows
if (value of text field 1 of aRow as text) is equal to ¬
(button returned of desiredOutput as text) then
set selected of aRow to true
exit repeat
end if
end repeat
end tell
end tell
tell application "System Preferences" to quit
BTW I'm on the new mavericks
 
Last edited by a moderator:
Try this :

Code:
tell application "System Preferences"
	launch
	activate
	tell application "System Events"
		get properties
		tell process "System Preferences"
			delay 3
			click menu item "Sound" of menu "View" of menu bar 1
			delay 2
			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
				copy (value of text field 1 of aRow as text) to the end of theOutputs
			end repeat
			tell application "Finder"
				activate
				set desiredOutput to display dialog ¬
					"Choose Sound Output: " buttons theOutputs default button "Headphones"
			end tell
			repeat with aRow in theRows
				if (value of text field 1 of aRow as text) is equal to ¬
					(button returned of desiredOutput as text) then
					set selected of aRow to true
					exit repeat
				end if
			end repeat
		end tell
	end tell
end tell
tell application "System Preferences" to quit

Instead of :

Code:
click menu item "Sound" of menu "View" of menu bar 1

you can do something like this :

Code:
tell application "System Preferences"
	launch
	activate
	reveal anchor "Output" of pane id "com.apple.preference.sound"
	tell application "System Events"
		tell process "System Preferences"
			set theRows to every row of table 1 of scroll area 1 of ¬
				tab group 1 of window "Sound"
			-- etc
		end tell
	end tell
end tell
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.