Getting the value of a popup button

I can’t quite figure out how to get the value of a popup button once it’s changed.

Say, I’m testing a script and I want a dialog to display the button’s current value after it’s been changed (This is what on mouse exit is for, yeah?)

Thanks in advance,

  • Phil

Greetings.

To get the current value of a popup button you need to get it’s title. To have a dialog alert you of the button’s current state, connect the menu itself to an “on choose menu item” event and then add the following code to your project. This code assumed that you have a popup button named “popupButton” in a window named “popupWindow”.

on choose menu item theObject
	-- See which popup button/menu was clicked
	if name of theObject is "popupButton" then

		-- Get the value of the popup button
		set currentPopupValue to title of popup button "popupButton" of window "popupWindow"
		
		-- Create a simple dialog box
		set dialogText to "You selected: "" & currentPopupValue & """
		display dialog dialogText buttons {"OK"} giving up after 5 attached to window "popupWindow"
		
		-- Set the list back to showing the first (default) item
		-- Added this in in case you might want it :-)
		set current menu item of popup button "popupButton" of window "popupWindow" to first menu item of popup button "popupButton" of window "popupWindow"

	end if
end choose menu item

Hope this helps…
j

Thanks! That helped a lot.

Now my problem becomes getting user defaults to store the popup button value as a number… the pref is setup right, but it always sets it to “0” when I change the setting.

The values of the button are just the numbers 1 - 9

Philn…
Check out the thread: “Newbie question - Saving preferences??” in this forum for my answers and code about saving to plist’s. If that doesn’t help post the troublesome part of your code and we’ll try to fix it.

j