Using bundled applications(.app file) as daemon/Agent

I have a .app file that I want to run as a daemon. Now there are two ways of running .app as a daemon/agent in macOS.

  1. using .app file : I can specify this in the daemon plist as:

     <key>ProgramArguments</key>
     <array>
         <string>/usr/bin/open</string>
         <string>/Applications/myApp.app</string>
     </array>
    
  2. using unix exe within .app file

     <key>ProgramArguments</key>
     <array>
       <string>myApp.app/Content/MacOS/MyApp</string>
     </array>
    

Basically I wanted to know what is the Apple recommendation on how we should be creating daemon plist.

For point 2, is it appropriate to use the unix executable within bundle?Will it not cause any issue in the running application?

Is will be helpful if there is some apple documentation to support this.

Approach 1 is deeply unsupported. Don’t do that.

Approach 2 is the one I recommend. Indeed, as things currently stand it’s the only way to ship a daemon that uses restricted entitlements. See Signing a daemon with a restricted entitlement.

IMPORTANT Apps and daemons are different things. In some situations it makes sense to bundle a daemon in an app-like wrapper, but that doesn’t make it an app. You cannot, for example, call AppKit from a daemon, regardless of how it’s packaged.

An variant of approach 2 is to install your daemon using SMAppService. You still have to do that MyDaemon/Content/MacOS/MyDaemon dance, but you can use BundleProgram and do it relative to the root of the containing app’s bundle.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Using bundled applications(.app file) as daemon/Agent
 
 
Q