Need help with UI Script problem

I’m trying to learn Applescript and have been playing around with controlling the System Preferences Application -specifically the SOUND pane. All I want to do is create a script to select an alert sound. Here is the script so far:

tell application “System Preferences”
activate
end tell
tell application “System Events”
tell process “System Preferences”
click menu item “Sound” of menu “View” of menu bar 1
delay 2
click radio button “Sound Effects” of tab group 1 of window “Sound”
click text field 1 of row 4 of table 1 of scroll area 1 of tab group 1 of window “Sound”
end tell
end tell


The line: click text field 1 of row 4 of table 1 of scroll area 1 of tab group 1 of window “Sound”
doesn’t seem to work. I’m trying to have applescript click on the 4th alert sound (Frog) but it does nothing. I’ve also tried using the “click at {x,y}” command with the proper x,y for the text at the 4th row and it doesn’t work either. Am I just stupid or perhaps there are problems with the UI Script Beta? Please oh please can someone help me? Thanks!

Scott :cry:

This might work:

tell application "System Preferences"
	activate
end tell
tell application "System Events"
	tell process "System Preferences"
		click menu item "Sound" of menu "View" of menu bar 1
		delay 2
		click radio button "Sound Effects" of tab group 1 of window "Sound"
		tell row 4 of table 1 of scroll area 1 of tab group 1 of window "Sound" to set selected to true
	end tell
end tell

– Rob

Hey Rob,
Thanks very much for your help with that problem. Setting the row selected to true worked great! I wish I’d thought of that! Anyways, I really appreciate all the help learning Applescript that your guys have provided.

Take care,
Scott

PS: Any idea why the 2 methods I tried didn’t work? (clicking the text field of the desired row or clicking at a specific {x,y} position)

Nope, I have no idea. If you plan to script the UI often, I highly recommend PreFab UI Browser. It can save a lot of time and I consider it essential. :slight_smile:

– Rob