Problem referencing another NSMenu in nib

Hi,

Here’s what I have, a nib file with two menu’s, the Main Menu and another one I added and connected to the Dock. I can enable/disable menu items from the Main Menu easily (set enabled of menu item 1 of menu 3 of main menu to false) but I can’t seem to manage it for the other menu. any help?

It’s a menu with only 3 menu items in it nothing more…

Thanks in advance

I have not tried this, but can you reference the 2nd menu at all? You say “of main menu” to ref the main menu, but is your dock menu called anything? Like “set myDockMenu to nib menu ‘dock menu’ of application bundle”. That’s just a made up example I just wrote. But you get the idea- you have to tell your dock menu to be the target of the statement. Then say “set enabled of menu item 1 of menu 1 of myDockMenu to false”.
Does that help at all?

Chris

I called my dock menu “DockMenu” and tried lots of stuff before (and just did your thing) but none of them work. I get this error :

The specified object is a property, not an element. (-10008)

But I think it may not be possible in vanilla ASS, because when I connect the menu items of the dock menu to the choose menu item handler I get this error:

Can't get <<class menI>> id 119 of item id 118. (-1728)

I tried that to get the super view of theObject but I got that error so I replaced the super view stuff with a simple display dialog and it gave the same error.

I also just found out that john8 has an example called DockMenu. I think that will be the thing I need so I’ll check it out later today. I’ll report back and try to find a solution why the above errors occured.

What john8’s example does is;

  • Get the NSMenu as a variable by using the awake from nib handler and setting a variable to theObject.
  • Then it deletes all menu items of the menu and creates new ones with an ObjC call method.
  • When you click a menu item, the ObjC code changes the title of a button and clicks that button.
  • In AS you have the code for when the button gets clicked and it displays a dialog with the title of the button.

I could be completely wrong but that’s how I think it works… Unfortunately, that’s not what I need, I want to have the option to enable/disable the menu items and do stuff when clicked. It’s a great example, a very nice one. But I won’t use it because of the “I click button” stuff. I know I can probably change all that but as far as my ObjC knowledge goes (not far at all) I don’t know how to do it. So I think I’ll just remove the dock menu.

Thanks anyway :smiley:

Hi,

as far as I know AppleScript Studio can only reference the main menu. Menulets or contextual menus can’t be accessed

Well,

John has another example called MenuApp, it transforms a normal menu into a menulet, it’s still accessible through the on choose menu item handler.

Jobu had a solution once of having a hidden window with a popup on it connected as the dock menu. It’s said to work with the on choose menu item handler but I -again- won’t use that because of it’s weird kind of way of getting the dock menu. The same as John’s DockMenu. So I think I’ll just remove the dock menu from my app.