0

I have a app with NSStatusItem on the menu bar. Now i want to use shortcut keys to call up the NSWindow which should be displayed right bellow the NSStatusItem. With mouse click i just get the position of status item with:

CGRect eventFrame = [[[NSApp currentEvent] window] frame];

But i have no idea how to get this position if i use shortcut to call the window. The NSStatusItem has a custom view.

A similar question is here How to get the on-screen location of an NSStatusItem but no one could give a solution.

Community
  • 1
  • 1
Quang Nguyen
  • 354
  • 1
  • 5
  • 20
  • Check the sample application from here: https://developer.apple.com/library/mac/samplecode/UIElementInspector/Introduction/Intro.html. I used a couple of times when trying to find out some stuff about the UI of my apps. It's based on the accessibility api provided by cocoa, however it might give you some clues. – Cristik Apr 30 '15 at 18:23
  • Have you checked http://stackoverflow.com/questions/5413784/how-to-get-frame-for-nsstatusitem - the answer from Crutt? – VolenD May 01 '15 at 09:27
  • 2
    Thanks! it's just my failure in the code. `NSRect frame = [[[[_menubarController statusItem] view] window] frame];` give me the correct frame what i need. – Quang Nguyen May 01 '15 at 10:18
  • 2
    Consider adding that as an answer, so that others can figure it out – Spotlight Jul 09 '17 at 03:29

0 Answers0