4 Replies
      Latest reply on Jan 31, 2017 8:28 PM by ocworld
      ocworld Level 1 Level 1 (0 points)

        How to launch background application (app bundle) and keep alive it on macOS?

         

        The application has roles of sending notification to notification center on macOS and processing notification actions such as "active".

         

        It should be 1)kept alive and 2)background application.

         

        I've been tried following steps.

         

        1. Adding a "Application is background only" key that has a "YES" value to an application project plist file

         

        2. Check that the app run as an background app, building and launching the app on xcode.

         

        3. The application is registered as LaunchAgent

        launch agent plist file key value

        <?xml version="1.0" encoding="UTF-8"?>

        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

        <plist version="1.0">

        <dict>

        <key>Label</key>

        <string>BUNDLEID</string>

        <key>ProgramArguments</key>

        <array>

        <string>MYAPPPATH/MY.app/Contents/MacOS/MYAPP</string>

        </array>

        <key>RunAtLoad</key>

        <true/>

        <key>KeepAlive</key>

        <true/>

        </dict>

        </plist>

         

        4. After loading the plist using launchctl, the app is launched. But It is not "background".

         

        5. Try again, registe the app as launchAgent after modifying a plist file referenced from http://stackoverflow.com/questions/18134992/how-can-i-start-a-program-app-with-launchdaemons-launchd

         

        <?xml version="1.0" encoding="UTF-8"?>

        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

        <plist version="1.0">

        <dict>

        <key>Label</key>

        <string>BUNDLEID</string>

        <key>ProgramArguments</key>

        <array>

        <string>/usr/bin/open</string>

        <string>-W</string>

        <string>MYAPPPATH/MY.app/Contents/MacOS/MYAPP</string>

        </array>

        <key>RunAtLoad</key>

        <true/>

        <key>KeepAlive</key>

        <true/>

        </dict>

        </plist>

         

        6. However, after reloading the plist, the app is still not "background".

         

        Is it possible to satify two that one is background launched app bundle and the other is keep alive that mean when the app is terminated, launch it again.