 macOS | Services | Launchd | WSO2

How to Use launchd to Run Services in macOS

Introduction to manage macOS service with examples.

Kosala Sananthana
The Startup
Published in
5 min readMay 29, 2019

In computing, launchd, a unified operating system service management framework, starts, stops and manages daemons, applications, processes, and scripts in macOS. It was introduced with Mac OS X Tiger and is licensed under the Apache License.— Wikipedia

If you’ve familiar with any version of Linux, surely you have worked with cron jobs. Basically, launchd is the cron in macOS. Other than executing scripts cron-style, launchd does a lot more. Like systemd on Linux, launchd is a replacement for a lot of old school Unix tools, like init, inetd, cron, etc.

At it’s core, launchd distinguishes daemons and agents. Daemons are system-wide services that always run in the background, while agents describe regular services that are to be executed on user-specific events. Daemons and agents are managed by launchd framework which can be controlled using the launchctl terminal command.

There are two main components in the launchd service creating process that you will need to follow.

  1. Job Definition : Define the service in special XML file.
  2. Operations : Control the service using command line utility.

📋 Job Definition

The behavior of a daemons or agents are defined in a special XML file called a property list (.plist) file. Depending on where it is stored it will be treated as a daemon or an agent. Services (Daemons and Agents) are saved as .plist files and can reside in one of the following folders according to your requirement as given below.

Image by launchd.info

launchd supports more than 36 different configuration keys in property list file and only main keys that required for a basic service are described in the below. ( from launchd.plist(5) manual)

Label <string>
This required key uniquely identifies the job to launchd.
Program <string>
This key defines what to start. If…



Kosala Sananthana
The Startup

PhD Student @ AχL — Monash University | Former Senior Software Engineer @ WSO2 Inc. | Writer @ The Startup/Better Programming/Towards Data Science