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

tbme

macrumors newbie
Original poster
Aug 31, 2014
4
0
Hi
I have a problem with following script to change the output device:
Code:
set asrc to (choose from list {"Internal Speakers", "Soundflower (2ch)", "Soundflower (64ch)"} with title "Sound Picker" default items {"Internal Speakers"}) as text
if result is "false" then return

tell application "System Preferences"
	reveal anchor "output" of pane id "com.apple.preference.sound"
	activate
	
	tell application "System Events"
		tell process "System Preferences"
			select (row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is asrc)
		end tell
	end tell
	
	quit
end tell
It gives following error:
Code:
error "System Events got an error: Can’t get window \"Sound\" of process \"System Preferences\"." number -1728 from window "Sound" of process "System Preferences"
This code seemed to work in Mountain Lion, but now I'm testing this on the Yosemite public beta 2

Any help is appreciated!
 
Code:
 whose value of text field 1 is asrc
Looks a little sketchy to me.

I see objects like this in Mavericks:
Code:
 table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
 row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
 text field 1 of row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
 text field 2 of row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
 column 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
 column 2 of table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
 
Code:
 whose value of text field 1 is asrc
Looks a little sketchy to me.
I forgot to mention that I simply found that somewhere. It seemed to work for the person (original post)

Nevertheless, I don't really understand what you try to say with your second part of code. I'm looking for the solution for applescript not finding window "Sound".
 
That second bit isn't code, it's a list of objects in the "Sound" window.
I think what you need to do is check the value of:
Code:
text field 1 of row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
Perhaps the value of text field 1 of row 2 as well.

From what I see, your code is likely finding the sound window OK, it's having trouble finding a textfield, within the Sound window, whose value is asrc.

You might try having your script do something like
Code:
set myval to text field 1 of row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" of application process "System Preferences" of application "System Events"
return myval
-Then check result in AppleScript Editor.
That should let you ferret out the Mavericks value of the textfield you want to work with.
 
I tried that and it gave the same error (can't find window "Sound") on that line that I added.

How did you find those objects? Maybe it's different for the Yosemite Beta?

EDIT: I have tried some things:
Code:
get name of front window
when the Sound window is on the foreground gives:
Code:
--> missing value
If I use "window 1" to do the commands, it does seem to work (it can find the names of the output devices)
 
Last edited:
Works on Yosemite DP4-DP5. Not working on Yosemite DP6 with the aforementioned error.

Code:
set asrc to (choose from list {"Internal Speakers", "Soundflower (2ch)", "Digital Out"} with title "Sound Picker" default items {"Internal Speakers"}) as text
if result is "false" then return

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"
		select (row 1 of table 1 of scroll area 1 of tab group 1 of window "Sound" whose value of text field 1 is asrc)
	end tell
end tell

tell application "System Preferences" to quit
 

Attachments

  • Screen Shot 2014-09-01 at 20.43.59.png
    Screen Shot 2014-09-01 at 20.43.59.png
    165.1 KB · Views: 315
Last edited:
I have found that using window 1 instead of window "Sound" does the thing.
Maybe I'll change it to "Sound" again when the official release is out.

Thanks for the help anyway!
 
I have made a script to choose my cinema display as my audio output. However, sometimes - seamly at random - I get an error message from the script.

Does anybody have any suggestions as to why I get an error?

My script:
Code:
	# Set Audio Out to Cinema Display	
	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"
			select (row 1 of table 1 of scroll area 1 of tab group 1 of window 1 whose value of text field 1 is "LED Cinema Display")
		end tell
	end tell
	quit application "System Preferences"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.