16

How do I create a Cocoa app that runs in the background (not in the dock, and not in the menu bar either; just in the background).

Does the app need admin privileges? I hope not. Actually it shouldn't, because it's enough that the app runs in the background for that user only, i.e. not for all users.

And I guess I can make it "launch when log-in" by just adding it to the user's Account Preferences, so that shouldn't be a problem.

Enchilada
  • 3,859
  • 1
  • 36
  • 69

2 Answers2

18

In your Info.plist set LSBackgroundOnly to 1.

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60
12

In your Info.plist, set LSUIElement to the string “1”.

The main difference is that a UI-element agent can have a UI (order in a window). A background-only app should be completely faceless; whatever UI it has should exist in a separate application or preference pane.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • make it `bool` `YES` not `string` `"1"` – Daniel Nov 25 '19 at 11:45
  • Interesting that it is now documented as being a Boolean: https://developer.apple.com/documentation/bundleresources/information_property_list/lsuielement?language=objc The old documentation was very clear that it was meant to be a *string* that could be set to "1": https://web.archive.org/web/20141004073224/https://developer.apple.com/library/mac/documentation/general/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/20001431-108256 Not sure if the facts changed, the old docs were wrong, or the new docs are wrong (though string "1" definitely works). – Peter Hosey Apr 09 '20 at 14:41