As of OS X 10.10 most of NSStatusItem has been deprecated in favour of the button
property, which consists of an NSStatusBarButton. It should work like a norma
Anton's solution is perfect. Here it is in Swift 3:
NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown) { [weak self] event in
if event.window == self?.statusItem.button?.window {
// Your action:
self?.togglePopover(self?.statusItem.button)
return nil
}
return event
}
I added an observer for NSApplicationWillResignActive
to close the popover and set the button's isHighlighted
to false
.