Activation Behavior of a Global Command Palette
To improve this, we can add
NSApplicationDelegateto our app and set the activation policy to.prohibitedin theapplicationWillFinishLaunching(_:)method. Then, in theapplicationDidFinishLaunching(_:)method, we can set the activation policy to.accessory(or.regularif 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: