Activation Behavior of a Global Command Palette
To improve this, we can add
NSApplicationDelegate
to our app and set the activation policy to.prohibited
in theapplicationWillFinishLaunching(_:)
method. Then, in theapplicationDidFinishLaunching(_:)
method, we can set the activation policy to.accessory
(or.regular
if we want the dock icon to be visible).This way, the app will launch without stealing focus.
[…]
We override the
close()
method and addNSApp.hide()
to deactivate the app after closing the window.By overriding the
cancelOperation(_:)
andresignKey()
methods, we ensure that our launcher will be closed when the user presses the Esc key or selects another window.
Previously: