title: popUpMenuPositioningItem:atLocation:inView: hangs when switching to another application
body: <p>I am working on a dockless application (<code>LSUIElement</code> true). The application pops up a menu when the user clicks on the corresponding <code>NSStatusItem</code>, or when a keyboard shortcut is used.</p>
  
  <p>My problem is that all methods to pop up a menu programmatically hang whenever the user switches to another application (using ⌘-TAB) without dismissing the menu first. I have tried <code>popUpMenuPositioningItem:atLocation:inView:</code>, <code>popUpContextMenu:withEvent:forView:</code>, and the corresponding method on <code>NSStatusItem</code> (<code>popUpStatusItemMenu:</code>).</p>
  
  <p>If the user dismisses the menu with the ESC key everything works fine, but if the user switches to a different application, the above-mentioned methods never return (they seem to run synchronously and return when the menu is dismissed). The application does not crash, and there are a couple of tricks to regain control (invoking exposé, or clicking on any <code>NSStatusItem</code> which pops up a menu).</p>
  
  <p>The problem disappears if the application has a dock icon (i.e. setting <code>LSUIElement</code> to false).</p>
  
  <p>This is the code popping up the menu when the keyboard shortcut is used:</p>
  
  <pre><code>[mainMenu popUpMenuPositioningItem:[mainMenu itemAtIndex:0]
                          atLocation:[NSEvent mouseLocation]
                              inView:nil];
  </code></pre>
  
  <p>And this is the code popping up the menu when the <code>NSStatusItem</code> is clicked:</p>
  
  <pre><code>- (void)mouseDown:(NSEvent *)event
  {
      [statusItem popUpStatusItemMenu:[statusItem menu]];
  }
  </code></pre>
  
  <p>The <code>mouseDown:</code> method is in the custom <code>NSView</code> attached to the <code>NSStatusItem</code>.</p>
  
  <p>Any idea on how to fix this?</p>
  
  <p>Thanks for your help.</p>
  
  <h2>Update</h2>
  
  <p>The problem is also linked to the application being activated (I use <code>[NSApp activateIgnoringOtherApps:YES];</code> before showing the menu, or in some cases it is not possible to navigate the menu with the keyboard).</p>