Setting value of a Pop Up Menu directly with GUI scripting

Is there a way to set the value of a pop up menu directly using GUI scripting, rather than making then menu pop up?

This script seems to run ok


tell application "System Events"
	tell process "iAlarm"
          set value of pop up button 2 of window "iAlarm" to "Radio"
	end tell
end tell

But doesn’t actually change the pop up menu. Do I have to somehow refresh the application, menu, or window to reflect the change? Just visually, this would be a little nicer than having the menu pop up over everything.

Thanks

This kind of thing might be possible in an application that has regular AppleScript support, ephramz - but I don’t think that’s the case with iAlarm. So we’re kinda stuck with emulating a user’s actions through UI scripting.

You should be able to change the value of a text field directly:

tell application "System Events" to tell window "iAlarm" of process "iAlarm"
	set value of text field -1 to "Hello"
end tell

However, because a pop up button has a different structure, its value is normally changed by selecting an item from the list of available menu items. In a UI scripting context, these don’t even exist until the menu is visible.

So you may have to go with an approach that displays both the menu - and the required menu item being selected:

tell application "System Events" to tell window "iAlarm" of process "iAlarm"
	tell pop up button 2
		click
		click menu item "Radio" of menu 1
	end tell
end tell