Skip to main content
https://img.shields.io/pypi/v/launchd.svg https://github.com/infothrill/python-launchd/actions/workflows/tests.yml/badge.svg?branch=main

launchd is a pythonic interface to interact with macOS’s launchd. It provides access to basic querying and interaction with launchd. It is implemented using the Objective C ServiceManagement framework as well as the launchd command line utility. Therefore, this python package can only be used on macOS

Examples

The relevant import statement is:

import launchd

Listing all launchd jobs:

for job in launchd.jobs():
    print(job.label, job.pid, job.properties, job.plistfilename)

Find the pid of a job:

>>> launchd.LaunchdJob("com.apple.Finder").pid
278

>>> launchd.LaunchdJob("com.example.fubar").pid
Traceback (most recent call last):
  File "launchd/launchctl.py", line 78, in refresh
    raise ValueError("job '%s' does not exist" % self.label)
ValueError: job 'com.example.fubar' does not exist

Detect if a job exists:

>>> launchd.LaunchdJob("com.example.fubar").exists()
False

launchd job properties (these come directly from launchd and NOT the .plist files):

>>> launchd.LaunchdJob("com.apple.Finder").properties
{'Label': 'com.apple.Finder', 'PlistPath': '/System/Library/LaunchAgents/com.apple.Finder.plist', 'Scope': 4, 'Status': 'unknown', 'StatusCode': None, 'Registered': True}

>>> launchd.LaunchdJob("com.apple.Finder").properties["Label"]
'com.apple.Finder'

Find all plist filenames of currently running jobs:

for job in launchd.jobs():
   if job.pid is None or job.plistfilename is None:
      continue
   print(job.plistfilename)

Job properties of a given job (this uses the actual .plist file):

>>> launchd.plist.read("com.apple.Finder")
{'POSIXSpawnType': 'App', 'RunAtLoad': False, 'KeepAlive': {'SuccessfulExit': False, 'AfterInitialDemand': True}, 'Label': 'com.apple.Finder', 'Program': '/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder', 'CFBundleIdentifier': 'com.apple.finder', 'ThrottleInterval': 1}

Installation

$ pip install launchd

or, if you prefer working from a local checkout:

$ python -m build
$ pip install dist/launchd-*.whl

Requirements

  • OS X >= 10.6

  • Python 3.10+

  • macOS 13+ for the SMAppService-backed job metadata API

SMAppService integration

Job metadata is now collected through Apple’s SMAppService API. Because that interface only exposes helper plists that the calling bundle can manage, launchd.jobs() now reports the property lists SMAppService can inspect (status, bundled configuration, etc.). pid/LastExitStatus therefore remain None in most cases, but properties["Config"] still contains the original plist contents. The low-level launchctl binary remains the implementation for load()/unload() until Apple publishes a direct replacement.

Development

Run the unit tests (example uses Python 3.10):

$ tox -e py310

Verify style/lint checks:

$ tox -e style

Build the source distribution and wheel:

$ python -m build

Publish via Twine (this rebuilds as part of the command):

$ tox -e release

Release files for launchd 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for launchd 1.0.0
File Size Uploaded
launchd-1.0.0.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for launchd 1.0.0
File Interpreter ABI Platform
launchd-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.1 kB

Release files / launchd-1.0.0.tar.gz

Download URL launchd-1.0.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c900814ac2c913340e652091484476c98e4d654cce2d9b202e994f5ee9516c47
BLAKE2b-256 checksum
How to use checksums
fb6dcdd865a62b46009bb159dc55ed928e0664eaaaf88de1b6b53a6c2d2e0963
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / launchd-1.0.0-py3-none-any.whl

Download URL launchd-1.0.0-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f9dcfc5c71f4c59a7a9f644e1a68f84628f0a6ec9f557e22ace9b4d5b2dc4767
BLAKE2b-256 checksum
How to use checksums
e1049e005540db523e5f90332683c70f460b208823e9f8f1504ba3decaf2ebfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

5 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page