1

I'm trying to write a small utility that attaches itself to the current main/key window. I've managed to make sure that the window cannot become key or main window, but it still shows up in the list of active applications when I use ⌘+tab.

The application should still be in the dock (so you can quit it and do other interactions), but I would rather that it didn't show up in the application list when pressing ⌘+tab.

I thought I had the answer when I discovered NSApplicationPresentationDisableProcessSwitching, but alas, that's system wide(!) which is certainly is not what I want.

Clearer
  • 2,166
  • 23
  • 38
  • 2
    Have you looked at being a status-bar-only app rather than being in the dock? You can still have a menu for interactions. I *think* that being in the dock goes hand-in-hand with being in the task switcher. – Rob Napier Dec 11 '18 at 14:25
  • @RobNapier I have not. Do you have a link handy, that will point me in the right direction? – Clearer Dec 12 '18 at 07:12
  • 1
    It has gotten really hard to find. I've built these myself, and know everything I'm looking for, and still it took me forever searching around to find anything that would show you how to do it if you didn't already know. This is a pretty good quick intro: http://www.johnmullins.co/blog/2014/08/08/menubar-app/ The short version is that you create an `NSStatusItem` (by calling `NSStatusBar.statusItemWithLength`), attach an `NSMenu` to it, and set `NSUIElement` in your Info.plist to avoid showing up in Dock. – Rob Napier Dec 12 '18 at 16:01
  • That's awesome! Especially, because I wanted to create a `NSStatusItem` anway. Feel free to make this an answer. – Clearer Dec 13 '18 at 13:11
  • 1
    @RobNapier Just adding `Application is an agent (UIElement)` to the info.plist with value = "YES" removes the app from both the dock and the `⌘+tab` cycle. – Clearer Dec 13 '18 at 13:16

1 Answers1

2

Add "Application is an agent (UIElement)" to the Info.plist (raw key: NSUIElement) to remove yourself from the dock. Then create a status bar item (NSStatusItem) to hold your menu.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610