MacOS: Know the difference between launch agents and daemons, and use them to automate processes
By now, you’ve probably heard about launch agents and daemons on macOS, but you may not know exactly what they are or how to use them properly. In this tutorial, we’ll go over the definitions of launch agents and daemons, and show you how to use them in your day-to-day life.
What is a Daemon?
A daemon is a type of software that starts up when your computer boots. These can range from hardware drivers for your hardware to things like file synchronization services. Most Daemons take care of tasks without you having to think about it. For example, Dropbox has a daemon running in the background so it can sync your files across different devices without you needing to do anything.
The best part about Daemons is that they’re mostly event-driven meaning they only start if an event happens–and most people are barely aware these tasks are happening at all! There’s one big exception to this rule though: Launch Agents. Launch Agents don’t need events to activate, but instead get their commands via properties which are set beforehand (or with the help of System Preferences). If you ever notice an app popping up randomly on your screen or suddenly acting strange after a Mac restart, chances are there’s a Launch Agent misbehaving.
What is a Launch Agent?
Launch Agents are files which start automatically with your Mac computer on a schedule or when another event happens. They don’t need any user intervention as they are always running in the background. To activate a Launch Agent all you have to do is click on it in Launchpad. You can also deactivate a Launch Agent by right-clicking and selecting Deactivate.
Launch Agents will continue to execute even if you log out of your account. There’s no way to stop them from executing except for shutting down your computer. What is a Daemon? A daemon is an application that runs in the background without needing any input from the user. Unlike Launch Agents, Daemons are not visible from Launchpad and users must explicitly open their application before execution starts. The advantage of using Daemons over Launch Agents is that their execution won’t interfere with other processes running on your system (e.g., Mail app).
Using both Daemons and Launch Agents
Both Launch Agents and Daemons help make things more efficient on your Mac. But how do you know which one you need? How can they be used to automate tasks on your Mac? This post will cover the basics of these two powerful tools as well as help answer these questions. A daemon is a program that continues running in the background without a user’s attention or input. They are typically activated by entering commands in Terminal or using Automator or Keyboard Maestro shortcuts (see list below).
Once an item is set up as a daemon it doesn’t need you to run it again after each reboot because the software handles those duties automatically. Launch Agents are programs that must be manually launched from the command line with system triggers. They don’t stay active all the time but instead wait for certain conditions to occur before performing a task. When something happens such as you plugging in your iPhone, macOS checks for any relevant Launch Agent apps to perform their assigned task when this event takes place. For example, if you have Google Chrome installed on your computer and plugged into power at 10pm every night at 10pm it launches Google Chrome without needing any additional input from you.
Launching Applications with Daemons vs. Launch Agents
To launch an application automatically when a computer starts up, use a daemon. There are several different ways to start an application as a daemon. The most obvious way is to click on a shareware program’s icon in Finder and choose ‘Open’ or ‘Open and run’. In this example we’ll assume you want to run Memtest86+, which is not in the list of items that appears when clicking on an icon in Finder, so instead open Terminal (searchable by typing ‘Terminal’). To start Memtest86+ running as a daemon type Sudo /sbin/memtest without quotes (without quotes it will ask for your password), then hit enter. In this example we’re using Sudo because we want memtest86+ running with root privileges.
Automating your computer with Cron Jobs
Utilizing Cron Jobs is a good way to automate processes on your computer. They are basically scheduled tasks that execute at a particular time, date or interval. With your chosen actions in place and running smoothly you can do more with less hassle. Creating Cron Jobs may sound intimidating but they’re actually pretty easy. All you need is access to Terminal (/Applications/Utilities/) and an understanding of basic Unix commands like ‘crontab’. Once they’re set up, they take very little maintenance.
To view your available cron jobs just type crontab -l into Terminal followed by pressing Enter on your keyboard. If you have any old cron jobs saved, then delete them first. It’s not uncommon for an old job to be conflicting with a new one and so it needs deleting before setting up anything new. In order to create a new Cron Job all you need is two parts; the scheduling details which include what command will be executed as well as when it should run, and then its contents which will comprise whatever specific steps are needed for this job to be completed successfully. If using Safari browser please see below for how-to tutorial video!