There are four popular ways of getting software to run whenever your Mac starts up, depending on whether it’s installed as a Login Item, or as a LaunchAgent or LaunchDaemon. This article looks at the differences between these mechanisms, so that you can decide which to use in each case, understand what can go wrong with them, and how to fix them.
Leave it running at shutdown
The simplest way to have an an app opened for you when you next start up is just to leave the app running when you shut down or restart. This does, of course, rely on you remembering to check that the app is running beforehand.
Add it from the Dock
There’s a quick and easy way to add apps which are already in the Dock to the Login Items list (discussed below): click and hold on their icon in the Dock until its menu pops up. In that, select Options, then the Open at Login command.
launchd
launchd
is a generally reliable way for a user to set an app or tool to run at startup. As I explained earlier this week, creating an appropriate Property List in one of the LaunchAgents or LaunchDaemons folders in /Library will ensure it’s run before you log in, which probably isn’t what you intend. Instead, you’ll more likely want to install yours in ~/Library/LaunchAgents instead, so that it’s launched once you have logged in.
Setting the RunAtLoad key to true tells launchd
to run the service or app then. To launch an app, set the ProgramArguments key to load the executable code within the app bundle, for example at AppName.app/Contents/MacOS/AppName. Remember that anything with a GUI must be a LaunchAgent.
Login Items
These are controlled quite differently, through LaunchServices rather than launchd
, which runs later following startup. You can set any app, service, or other executable code to run at startup by adding the item to the list of Login Items in the Users & Groups pane in System Preferences.
Once added, LaunchServices puts them into its list of apps to launch at startup, which in Sierra and earlier used to be located in ~/Library/Preferences/com.apple.loginitems.plist. Since High Sierra, that has moved, changed its extension, and the file structure, to ~/Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btm
That file isn’t intended to be maintained directly by the user. The new format is opaque: although a Property List, it is now a keyed archive containing objects which are referenced by UUID, and unsuitable for manual editing.
In addition to using the Dock menu or the Users & Preferences pane, you can add and remove Login Items using a scripting language; for example, in AppleScript
tell application "System Events" to make login item at end with properties {path:"/Applications/MyApp.app", hidden:false}
adds MyApp.app as a Login Item,
tell application "System Events" to get the name of every login item
lists all Login Items, and
tell application "System Events" to delete login item "name"
removes the named Login Item from the current list.
Login Items are better suited to apps of any size which have significant user interfaces, and anything which a user wants to control easily. Many apps, such as menu bar or ‘Status Bar’ apps, offer the user the option of installing them as a Login Item. Unfortunately, particularly when this is done for an app provided through the App Store, this turns out to be a complex development task which requires a helper app.
Sorting out LaunchServices problems isn’t easy. If you’re seeing weird things going on with your Login Items list, one possible solution is to start from scratch by trashing the current file, restarting, and setting up your Login Items again. Note that in some versions of macOS, until there is at least one Login Item, the settings file may not even exist.