At first glance, this button seemed ideal for what I’m trying to do: Organize scripts by categories on a compact toolbar. The first item in a pulldown is not a selectable item, it’s the name of the category. Then rest of the items can be accessed, at least in theory, by using the “on choose menu item” handler.
But it’s given me nothing but grief. Often, selecting a menu item generates the message “NSReceiverEvaluationScriptError: 3 (1)” Sometimes, I get a build that works, only to see if break when I move the app to another folder or another disk.
I’m about to rebuild this project using ordinary popup buttons, Can anyone post some information on how to use this critter?
I use them all the time with no problem. I do exactly as you suggest attaching the “choose menu item” handler to them. Are you using Xcode or Project Builder? On which OS?
Each menu item is attached to the choose menu item event. From another thread, I picked up a tip about not attaching the menu itself, tho that doesn’t seem to matter.
The top of the handler looks like this:
on choose menu item theObject
set objName to (get name of theObject)
set objTitle to (get title of theObject)
end choose menu item
I’ve checked, and each menu item has both a name and a title.
When it works, I use the two variables to load an external script file and run one of its subroutines. When it breaks, I get the aforementioned “NSReeceiver…” error.
Even when the app builds and runs OK, it seems to break if I move it to another folder or disk.
I don’t attach the handler to each menu item, just to the popup button itself:
on choose menu item the_object
set object_name to name of the_object as string
my update_status("choose menu item " & object_name)
if object_name is in {"popup", "pulldown"} then
set the_selection to (title of current menu item of the_object as string)
log ("You selected "" & the_selection & "" from "" & object_name & "".")
end if
end choose menu item