title: NSMenu programmatically select item
body: <p>I'm writing a plugin for application - custom keyboard shortcut. I can traverse through its views.
  I need to open popup menu, select item in it, then open its submenu and select some item in submenu.</p>
  
  <p>For now I'm only able to open top popup menu by sending <code>performClick:</code> to related <code>NSPopUpButton</code> element.</p>
  
  <p>How can I programmatically select item in menu and open its submenu?</p>
  
  <p>I've tried:</p>
  
  <ul>
  <li>call <code>selectItem:</code> on the <code>NSPopUpButton</code> (and related <code>NSMenu</code>). No luck and I see a notion in the <a href="https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSPopUpButton_Class/Reference/Reference.html" rel="nofollow noreferrer">doc</a>: "Note that while a menu is tracking user input, programmatic changes to the menu such as adding, removing, or changing items on the menu is not reflected"</li>
  <li>send keyboard events (using <a href="https://stackoverflow.com/questions/9318690/generate-keyboard-events-for-the-frontmost-application">this answer</a>). No luck - may be because I'm holding some keys at the moment of sending those events</li>
  <li>to find any info on how to do it via Accessibility API, but I just can't find anything on how to use it on current Application (or even on any other application, but with Objective-C)</li>
  </ul>