Thursday, February 15, 2024

Activation Behavior of a Global Command Palette

Art Lasovsky:

To improve this, we can add NSApplicationDelegate to our app and set the activation policy to .prohibited in the applicationWillFinishLaunching(_:) method. Then, in the applicationDidFinishLaunching(_:) 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 add NSApp.hide() to deactivate the app after closing the window.

By overriding the cancelOperation(_:) and resignKey() methods, we ensure that our launcher will be closed when the user presses the Esc key or selects another window.


Comments RSS · Twitter · Mastodon

Leave a Comment