Another newbie question: Ostensibly about popup menus, but..

…more in the line of basic AS Studio functionality.

I am starting to understand a little how Applescript and AS Studio interact. However, I continue to stumble over a series of basic symatics. So far you folks have all been a HUGE help :slight_smile: and I am once again turning to you.

I have the code show below. I am creating properties to hold not only the popup button, but also its menu object. Then, later on, I am setting those objects and trying to access them via code. You can see where my code is failing by reading the comments. Of course, I have a simple work-around but I really want to learn this stuff so…

anyone have any ideas as to why the third way of adding to the menu items of the popup button is failing?

Thanks again!


property popShow : popup button
property mnuShow : menu

on awake from nib theObject
	set popShow to popup button "popShow" of window "frmMain"
	set mnuShow to menu of popShow
	--this works
	delete every menu item of mnuShow
	--these work
	make new menu item at the end of menu items of menu of popup button "popShow" of window "frmMain" with properties {title:"cn", enabled:true}
	make new menu item at the end of menu items of menu of popShow with properties {title:"bb", enabled:false}
	--this fails with an error of NSContainerSpecifierError(3)
	make new menu item at the end of menu items of mnuShow with properties {title:"--", enabled:false}
end awake from nib

There are quirks to applescript/ASstudio that do not always SEEM logical at first, and this is one of them. It is not possible (as far as I’ve found) to save a reference to a menu of a popup button. I believe it is because the menu of a popup button is not a true NSMenu object, but an abstract object created internally so the appkit can understand your code. If it were an actual menu object, you could click on it in IB and modify it’s properties and work with it directly. So, when you try to work with a representation of the object (as in a variable), it looks for the actual object to work with…which of course isn’t really there. When you hard code “…menu of…” this is the only syntax it understands because it uses this specific command to reference the “menu” of a popup button.

You’ll just have to add a few more words and do it one of the other ways you’ve found that actually work. Everywhere you want to use ‘mnuShow’, you’ll have to use ‘menu of “popShow”’ instead. Sorry.



Thanks again for your help!