There is a method -[NSStatusItem setView:] . When you set a custom view for your status element, that view is automatically inserted into a special window on the status bar. And you can access this window using the method -[NSView window] to observe its NSWindowDidMoveNotification :
- (void)applicationDidFinishLaunching:(NSNotification *)notification { NSStatusItem *statusItem = [self newStatusItem]; NSView *statusItemView = [self newStatusItemView]; statusItem.view = statusItemView; NSNotificationCenter *dnc = [NSNotificationCenter defaultCenter]; [dnc addObserver:self selector:@selector(statusBarDidMove:) name:NSWindowDidMoveNotification object:statusItemView.window]; } - (void)statusBarDidMove:(NSNotification *)note { NSWindow *window = note.object; NSLog(@"%@", NSStringFromRect(window.frame));
You will be notified every time the status bar becomes visible or hidden and when your icon is moved. This is your chance to update the location of the popup panel.
source share