NSDatePicker in NSStatusBar NSSMenuItem not receiving input
<p>A while back I wrote a simple calendar menu bar widget called <a href="http://shauninman.com/archive/2011/10/20/day_o_mac_menu_bar_clock" rel="nofollow noreferrer">Day-O</a>. The calendar uses the stock NSDatePicker nested inside an NSView inside an NSMenuItem in an NSMenu added to an NSStatusItem. The app has an activationPolicy of <code>.accessory</code> (originally set via the plist's "Application is agent" bool). At some point (maybe with the El Capitan update?) the calendar stopped responding to input. When the app first launches you can click the status bar item to expand the menu and interact with the calendar and it responds to user input as expected. But once the application loses that initial focus the calendar stops responding to input. </p>

<p>I think I've tracked the issue down to the app not activating after initially resigning active. The problem is that if I try to manually activate the app when the menu bar item is clicked (using <code>NSApp.activate(ignoringOtherApps:true)</code>) the menu (you just opened) is dismissed.</p>

<p>I've also tried telling the window to make the NSDatePicker the first responder but that doesn't seem to have any effect either.</p>

<p>How do I get NSDatePicker in a menu item to accept user input when the status bar app is not the active app?</p>

<hr>

<p><strong>Edit:</strong> Simplest code to illustrate the problem (add this to an AppDelegate in a new macOS Cocoa app):</p>

<pre><code>let statusItem = NSStatusBar.system().statusItem(withLength:NSVariableStatusItemLength)
func applicationDidFinishLaunching(_ aNotification: Notification) {
    NSApp.setActivationPolicy(.accessory)

    statusItem.button?.title = "Calendar"

    let menu = NSMenu()
    let item = NSMenuItem()
    let picker = NSDatePicker(frame: NSRect(x: 0, y: 0, width: 140, height: 148))
    picker.datePickerStyle = .clockAndCalendarDatePickerStyle

    item.view = picker
    menu.addItem(item)

    statusItem.menu = menu
}
</code></pre>

<p>Launch the app, click the menu item, and click around the calendar. Then click on another app, then click back on the menu item again. The calendar no longer responds to clicks.</p>