Skip to main content

pythonic interface for OS X launchd

Project description

https://img.shields.io/pypi/v/launchd.svg https://travis-ci.org/infothrill/python-launchd.svg?branch=master

launchd is a pythonic interface to interact with OS X’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 OS X

The python objective C bridge contains some special types. This package strips off all non built-in type information and returns pure python data.

Examples

The relevant import statement is:

import launchd

Listing all launchd jobs:

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

Find the pid and laststatus of a job:

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

>>> launchd.LaunchdJob("com.apple.Finder").laststatus
0

>>> 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
{'OnDemand': 1, 'PID': 278, 'PerJobMachServices': {'com.apple.coredrag': 0,
'com.apple.axserver': 0, 'com.apple.CFPasteboardClient': 0,
'com.apple.tsm.portname': 0}, 'LimitLoadToSessionType': 'Aqua',
'Program': '/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder',
'TimeOut': 30, 'LastExitStatus': 0, 'Label': 'com.apple.Finder',
'MachServices': {'com.apple.finder.ServiceProvider': 10}}

>>> launchd.LaunchdJob("com.apple.Finder").properties["OnDemand"]
1

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.kextd")
{'ProgramArguments': ['/usr/libexec/kextd'], 'KeepAlive': {'SuccessfulExit': False},
'POSIXSpawnType': 'Interactive', 'MachServices': {'com.apple.KernelExtensionServer':
{'HostSpecialPort': 15}}, 'Label': 'com.apple.kextd'}

Installation

$ pip install launchd

or, if you want to work using the source tarball:

$ python setup.py install

Requirements

  • OS X >= 10.6

  • Python 2.7, 3.2+

Release history

0.1.2 (September 2020)

  • added tox.ini for easier testing accross interpreter versions

  • added travis test setup

  • fixed incompatibility with launchctl in test code

  • fixed a typo in the README

0.1.1 (November 2013)

  • Fixed a bug in launchd.plist.read() when no scope was specified

0.1 (November 2013)

  • Focus: initial public release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

launchd-0.1.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

launchd-0.1.2-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file launchd-0.1.2.tar.gz.

File metadata

  • Download URL: launchd-0.1.2.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.8

File hashes

Hashes for launchd-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f353b79764b58c5e94dc72706722814dd9c4d65dd0355766902f9dc0e55736bc
MD5 263541c493454910ffd2f9fd2dcdfca4
BLAKE2b-256 79669aae82afa47799faf77a9c36de2c488548f69275d60a7eb1bb896aa70c7c

See more details on using hashes here.

File details

Details for the file launchd-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: launchd-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.8

File hashes

Hashes for launchd-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14596e744b056c5bdb1c9db0d8028746254c8cfa48af603a9566a3ee4bcc43cf
MD5 c8f78bc5c7e75e970a76c5a373e658d9
BLAKE2b-256 ff3b131b9007470a5a03bda81f6611e16403e40e60f88c25ba5829a9f25af767

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page