more popup buttons in one window


I am a little stuck with several popup buttons in one window.

I used the “on choose menu item” to get the value of button1, then an “end choose menu item”. Now the user should select a value from button2 but the script error tells me that the choose menu handler is specified more than once.

How to specify more than one choose menu handlers in one script targeting different popup buttons in one window?

Thanks for any advice.


Just had a play, this is new to m as I have not used them before… but this seems to work.

1, Select the first Pop up Button ( NSPopUpButton)
note: Not the Pop up Button Cell

2, In the Applescript inspector: link the Pop up Button to the script and
Tick choose menu item (under the menu events)

3,Select the first item (Item 1) in the menu ( NSMenuItem)
4, In the Applescript inspector: give it a unique name. ( you do not need to link it AFAICT)
5,Repeat for each menu item in that pop up.

Now do 1 to 5 for the second Pop up Button ( NSPopUpButton).

In the script you can do something like this

on choose menu item theObject
	set thetheObjectName to name of the current menu item of theObject as Unicode text
	(* pop up 1 menu items *)
       	if thetheObjectName = "Item 1pop1" then say "popup  1, item 1"
	if thetheObjectName = "Item 2pop1" then say "popup  1, item 2"
	if thetheObjectName = "Item 3pop1" then say "popup  1,  item 3"
	(* pop up 2 menu items *)
	if thetheObjectName = "Item 1pop2" then say "popup  2, item 1"
	if thetheObjectName = "Item 2pop2" then say "popup  2, item 2"
	if thetheObjectName = "Item 3pop2" then say "popup  2, item 3"
end choose menu item


additionally to Mark’s explanation I’d like to make clear, that you can connect multiple UI elements to one event handler
and distinguish each element by the reference theObject

for example

on choose menu item theObject
	if (get name of theObject) is "popup1" then
		-- handle popup button 1
		-- handle popup button 2
	end if
end choose menu item


Thank you both for your fast replies.
I used Stefan’s suggestion which was ideal fo my script.