{"id":42126,"date":"2024-02-15T16:09:18","date_gmt":"2024-02-15T21:09:18","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=42126"},"modified":"2024-02-15T16:09:18","modified_gmt":"2024-02-15T21:09:18","slug":"activation-behavior-of-a-global-command-palette","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/02\/15\/activation-behavior-of-a-global-command-palette\/","title":{"rendered":"Activation Behavior of a Global Command Palette"},"content":{"rendered":"<p><a href=\"https:\/\/multi.app\/blog\/nailing-the-activation-behavior-of-a-spotlight-raycast-like-command-palette\">Art Lasovsky<\/a>:<\/p>\n<blockquote cite=\"https:\/\/multi.app\/blog\/nailing-the-activation-behavior-of-a-spotlight-raycast-like-command-palette\"><p>To improve this, we can add <code>NSApplicationDelegate<\/code> to our app and set the activation policy to <code>.prohibited<\/code> in the <code>applicationWillFinishLaunching(_:)<\/code> method. Then, in the <code>applicationDidFinishLaunching(_:)<\/code> method, we can set the activation policy to <code>.accessory<\/code>(or <code>.regular<\/code> if we want the dock icon to be visible).<\/p><p>This way, the app will launch without stealing focus.<\/p><p>[&#8230;]<\/p><p>We override the <code>close()<\/code> method and add <code>NSApp.hide()<\/code> to deactivate the app after closing the window.<\/p><p>By overriding the <code>cancelOperation(_:)<\/code> and <code>resignKey()<\/code> methods, we ensure that our launcher will be closed when the user presses the Esc key or selects another window.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/11\/16\/command-bars\/\">Command Bars<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>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.[&#8230;]We override [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-02-15T21:09:20Z","apple_news_api_id":"5e958409-cc3d-4714-81aa-7a16757e5904","apple_news_api_modified_at":"2024-02-15T21:09:20Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AXpWECcw9RxSBqnoWdX5ZBA","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[69,30,2385,71],"class_list":["post-42126","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-cocoa","tag-mac","tag-macos-14-sonoma","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=42126"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42126\/revisions"}],"predecessor-version":[{"id":42127,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42126\/revisions\/42127"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=42126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=42126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=42126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}