I have an app that sits in the menu bar, and when you click on the button it presents an NSPopover.
That all works fine, but I want an NSSearchField to become the first responder, so a user can then type straight in the box.
However, if the app was not already selected, it won't work. And although it looks like the search box is active, the keyboard input goes to the previous app that was open, because technically it is still the active window.
I've seen a few questions about things like this, but they all require objc methods like makekeyandorder, or just stuff that won't apply to an NSPopover.
So my question is - Is there a way that when the button is pressed, I can then force the application to become the active app?
I had a wild guess and tried NSApplication().sharedApplication().becomeFirstResponder()
, but no luck.
If there's another way to do it, that I've just missed completely, then please let me know!
I fixed it myself in the end, it turned out to be a very simple fix as expected.
All I needed to to was call NSApplication.sharedApplication().activateIgnoringOtherApps(true)
in the ViewControllers viewDidAppear()
method.
It fixes everything!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With