Home/Glossary/What are launchd and a LaunchAgent on macOS?

What are launchd and a LaunchAgent on macOS?

Updated · airankrush

Term · launchd and LaunchAgent

launchd is the system service in macOS that starts and supervises background programs. It is the first thing to run after startup, and every other process is launched by it. If you want a program to start on boot, run on a schedule or restart automatically after a crash, you write a plist configuration file and hand it to launchd. The configurations come in two kinds. A LaunchAgent runs after a particular user logs in, as that user, and can reach the desktop and the graphical interface. A LaunchDaemon runs as soon as the system starts and does not depend on anyone logging in, but cannot reach the graphical interface. A configuration placed in the user folder ~/Library/LaunchAgents applies only to that user, and creating it needs no elevated privileges.

How it relates to renting a remote Mac

You can use launchd normally on a rented Mac, and it is the proper way to make tasks come back by themselves after a restart.

  • For tasks that need a desktop (screen-operating agents, browser automation), use a LaunchAgent. It starts only once a user has logged in to the desktop, and whether the machine logs in automatically after a restart is whatever your delivery notes say.
  • For always-on services that need no interface, you can use a LaunchDaemon. An admin account can create one.
  • Do not disable or delete entries already in the system that you did not create. Some of them are components for platform management and remote control, and once they are stopped the machine may drop out of contact. If you see an entry you do not recognize, ask support first.
  • Write absolute paths for both the program path and the log path in the configuration. A program started by launchd does not get the environment variables you set up in your terminal, which is the most common reason for "runs fine by hand, fails on auto-start".

For how it pairs with tmux, see how to keep long tasks running.

FAQ

Can I still use cron on macOS?

Yes, the system still ships with cron. launchd is the way Apple recommends. Its advantages are that it can relaunch a program after it exits and can catch up on scheduled jobs missed while the machine was asleep.

The configuration is written but nothing runs. What should I check first?

First confirm the file is in the right folder, has the plist extension and has been loaded. Then look for errors in the log file named in the configuration. A path written as a relative path and missing environment variables the program depends on are the two most common causes.

Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support

Back to home · Glossary