How to add an application as a login item for all users in Mac OSX

1.2k Views Asked by At

I am trying to add an application as login item for all users by creating an launchd plist and copying it in /Library/LaunchAgents and also by loading it.

Plist is

<?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>com.testapp.UserAgent</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Applications/TestAgent.app/Contents/MacOS/TestAgent</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>KeepAlive</key>
        <false/>
</dict>
</plist>

RunAtLoad will launch the application at every login. It is working for me when I login in to all different user accounts in my machine but if I quit it manually then also it is launching by itself.

How can I make it to launch only once for each login and if I quit it then it should not be launched by itself.

1

There are 1 best solutions below

6
jvarela On

The best resource to know how to use launchd, the daemon that launches processes on macOS is here:

https://www.launchd.info

In here, it is well explained what other settings you can use apart from RunAtLoad or together with it.

For example, in your case, you could use the key KeepAlive as follows:

 <key>KeepAlive</key>
 <dict>
    <key>SuccessfulExit</key>
    <false/>
 </dict>

This would only relaunch your process if it exited with a code different than 0, which normally denotes some abnormal situation or error. If the exit is normal then your process will not be relaunched by launchd.

Check the tab Configuration on this site to know which other configurations you could use.