Customize NSToolbar context menu on El Capitan?

Is there a way to customize the context menu that pops op when irght clicking on a toolbar (or the tiel bar of the window containing it)?

XCode seems to manage to only keep the "Hide Toolbar" menu item (I don't want ot go that far), but I can't find a way to access the NSMenu.


Here's what I tried so far:

  • tried to get to the menu as I did on previous OS X versions (as explained here: http://stackoverflow.com/questions/8413111/how-to-customize-the-context-menu-of-nstoolbar): the returned NSMenu is nil
  • tried to override rightMouseDown: in the NSWindow containing the toolbar: the method is not called
  • tried to override menuForEvent: in the window's content view (I replaced the default content view with a custom NSView for this): the method is not called
  • tried to override rightMouseDown: in the window's content view (I replaced the default content view with a custom NSView for this): the method is not called

Replies

I actually found the answer by inspecting things in the debugger and tinkering a bit. On El Capitan, a working solution is to get the menu as such:


NSView * theContentView = myWindow.contentView; 
NSMenu * theCustomizeMenu = theContentView.superview.menu;

Many thanks.