I am developing a non-sandbox macOS app which is not going to be released in App Store, and I want to make the app to run when user log in.
The current method I have found is to use Service Management framework and a helper app, which needs to sign this app. The former valid way was LSSharedFileList, but this method doesn't work in macOS 10.14.
Is there a way I can make this simple app start at login?
You can register any app with
launchedto run as a user agent.In this example, an app named On Startup will be launched whenever the user logs in.
Step 1
You'll need to create a "launchd.plist" file to describe the service. In this example, you create a file named
com.yourdomain.onstartup.plistwith the following content:The key point is the
RunAtLoadproperty that tells launchd to start the process when the user session loads.(Note: you can create this file by building a dictionary and writing it as a property list.)
Step 2:
Install that file in
~/Library/LaunchAgents. This is where launchd looks for per-user launchd configuration files.Step 3:
Execute the command
or simply wait until the system restarts.
The
bootstrapcommand tells launchd that a new service wants to be registered and activated immediately, but all of the files inLaunchAgentswill get registered automatically the next time the user logs in.If you need your app to run all the time, consider adding a
KeepAliveproperty. And there are about a billion other options.Step 4:
To stop your app from starting again at login, delete the
com.yourdomain.onstartup.plistfile.If you've set the
KeepAliveproperty, you'll also want to invokelaunchctl bootout gui/501/com.yourdomain.onstartupcommand to stop the service and unregister it immediately. (Note: this will kill your app.)See
man launchd.plistman launchctlmacOS Daemons and Services