disable menu item

its pretty simple, i’ve got a menu item on my file menu, and i want to disable it dynamically… i tried:

set enabled of menu item “codefolder” of menu item “file” of menu “main menu” to false

any ideas?

There’s nothing wrong with your code. What you may not be aware of is that the default menu’s do not come prenamed with an applescript name. Also, be careful that you do not confuse the main menu item with the menu of that item. Here’s a hierarchy showing what I mean…

main menu (NSMenu)
	> "File" (NSMenuItem)
		- menu (NSMenu) --> Note the "hidden" menu
			> "New" (NSMenuItem)
			> "Open" (NSMenuItem)
			> "codefolder" (NSMenuItem)
	> "Edit" (NSMenuItem)
		- menu (NSMenu)
			> "Undo" (NSMenuItem)

Note that the File “menu” is actually a menu item of the main menu. This menu item has it’s own submenu, of which the menu’s items are children. When in IB, if you click on the “File” Menu and it is CLOSED but highlighted, you are working with the menu item of the main menu. If you click on the “File” menu and it’s OPEN, you are modifying the menu of the menu item. This is where you want to insert the name “File” as it’s applescript name… so when you insert the code below you are correctly referencing the menu named File.

set enabled of menu item "codefolder" of menu "File" of main menu to false
-- OR --
set enabled of menu item "codefolder" of menu 2 of main menu to false

Sorry if that’s a bit confusing. You may have to get into IB and click on the menu and menu items to get a feel for what I’m saying. It’s kind of like the difference between a text view and the enclosing scroll view, you just have to get used to referencing them and naming them correctly.

j

How do you get reference to a menu item that is in a second NSMenu? I have created a Menulet that pulls down an NSMenu named “DropMenu” …I can’t figure out how to reference it. I have no problem referencing stuff in the main menu.