4

I'm looking for a way to have my program started when user logins or when system boots up. The program needs to have root privilege and it needs to display some UI stuff on the top menu bar.

I have tried using launchd to start it as daemon and agents. The problem is daemons can't have UI. And agents are run as the user so it doesn't have root privilege.

I also tried having a daemon to call a script using setsid() to have my program running in a different process group but that didn't help either. It just can't show any UI stuff.

I am new to OSX and really need some help about this.

tjlian666
  • 343
  • 5
  • 17
  • 2
    Let the daemon do the privileged stuff and the agent do the GUI. Then make the agent query the daemon for the data it wants to display. – LCC Jul 18 '14 at 02:17

1 Answers1

5

As you've correctly identified, a daemon can't display UI. What you need is a separate program that communicates with the daemon to provide the required UI.

There are various methods for the communication. If the design is suitable, the preferred method is to use XPC services, in which case, you'd create your main GUI app and make the daemon an XPC service of that application.

Alternatively, the GUI app can be a Launch Agent, so it is launched on login and you then need to provide the communication between the two processes. There are several methods to do this, such as using Distributed Notifications, TCP Sockets and Streams or local sockets

Whichever method you choose, in order for the daemon to provide UI, you must use a separate process.

Community
  • 1
  • 1
TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
  • Hi, i'm dealing with the same problem of root background processes, that cannot trigger the crashreporter "unexpected termination" window. do i need to handle all signals that cause unexpected termination and trigger the Dialog box ? – Zohar81 Feb 15 '16 at 12:20
  • @Zohar81, I suggest starting a different SO question for that, as it's beyond the scope of this question. – TheDarkKnight Feb 15 '16 at 14:04
  • I actually wrote question about it, but phrased it differently, since i haven't figure out the source of the problem at first, maybe you can take a look at the following link http://stackoverflow.com/questions/35390122/trigger-application-quit-unexpectedly-popup-when-os-x-deamon-crashes – Zohar81 Feb 15 '16 at 14:10