I manage to link successfully the menu items from the application, the file menu but not the demo menu. The items from this last menu are all disabled.

For the first two menus, I moved the handlers out of the script delegate and use the setTarget: method to set the applet as the target of the menu items. I tried to do the very same thing with the items from the Demo menu, carefully re-writing the handlers and making sure they were spelled right and using the same setTarget: method but it did not work at all.

Well, I did a cut and paste of every action title in the script so that a handler is in there, just as I did for the menu items in the ‘File’ menu (which work just fine) and along the lines seen in Code to set preferences (as in a Cocoa app)?. It seems like the first three menus for an applet (application, File and Edit) let themselves being connected right into the script but if you create a new menu, there’s something else that must be done.

OK, I’ll try that, with an applet that just create a new menu and doesn’t change the other three, and I’ll get back to you.

While I’m here and that you’re not far away, I was wondering if my way of creating menu, below,

set extraMenu to (current application's NSMenu's alloc()'s initWithTitle:(title of customMenu))
set customExtraMenu to (current application's NSMenuItem's alloc()'s initWithTitle:(title of customMenu) action:"" keyEquivalent:"") -- customMenu is a record containing the title (a string) and list containing info for the menu items
(customExtraMenu's setSubmenu:extraMenu)
(currentApplicationMenus's addItem:customExtraMenu) -- and then, a loop is use to fill this menu

Your code has some problems. First, action handlers must always take a single argument — you can’t have doDemo2(). Second, case is very important — the selectors in your code start with D but your handlers start with d.

Nonetheless, you’re right: they don’t work. I tried turning off autoenabling and forcing them to be enabled, but still no luck. I can’t think of any explanation, unfortunately.

Automatic enabling/disabling of menu items is usually controlled by the target implementing the method validateMenuItem:. If this returns true, the menu item will be enabled. It normally calls it’s superclass version (continue in AppleScript) if the item doesn’t match one the object doesn’t have a target for.

You can actually see this in the following code. The validation handler is simply returning true for testing:

You can see that the handler is being called, but for some reason its result is being ignored. I’m guessing this is a hole in the bridging mechanism, and that the value we return is not being converted to the expected BOOL type, and is thus not being interpreted correctly.

That leaves the nuclear option, which is probably fine here. This means turning off autoenabling completely — items will be enabled as long as they have an action and a target can be found, and as long as you haven’t set them to be disabled.

It’s a nuclear option because, for some reason, we have to use it for the main menubar, so if you’re relying on other items being enabled according to circumstances, you need to handle them manually too. So: