PyObjC ServiceManagement Framework
pyobjc-framework-servicemanagement provides Python wrappers for Apple's ServiceManagement framework on macOS. This framework offers a secure and object-oriented interface for interacting with `launchd`, primarily used for managing privileged helper tools. The library is actively maintained, with version 12.1 being the current release, and follows a regular release cadence with updates aligning to new macOS SDKs and Python versions.
Warnings
- breaking PyObjC 12.0 dropped support for Python 3.9. Projects requiring Python 3.9 must use PyObjC 11.1 or older.
- breaking PyObjC 11.0 dropped support for Python 3.8. Projects requiring Python 3.8 must use PyObjC 10.3 or older.
- breaking PyObjC 12.0 was temporarily yanked from PyPI due to incorrect `python_requires` metadata, erroneously claiming support for Python 3.9. Users attempting to install PyObjC 12.0 on Python 3.9 would encounter build errors.
- breaking The behavior of `__init__` for Python subclasses that also implement `__new__` was changed in PyObjC 10.3, leading to unexpected breakage for some projects. This change was partially reverted in 10.3.1 to reintroduce the ability to use `__init__` when a user implements `__new__`.
- gotcha PyObjC is a macOS-specific library and will not function on other operating systems like Linux or Windows.
- gotcha PyObjC 11.1 aligned the behavior of 'init' family methods (initializers) with Objective-C's Automatic Reference Counting (ARC) semantics. These methods now correctly 'steal' a reference to `self` and return a new retained object, which might affect custom memory management or complex instantiation patterns.
Install
-
pip install pyobjc-framework-servicemanagement
Imports
- ServiceManagement
import ServiceManagement
Quickstart
import ServiceManagement
import objc
# Example: Accessing a constant from the ServiceManagement framework
# Note: Actual use of ServiceManagement APIs (e.g., SMJobSubmit, SMJobBless)
# requires significant macOS-specific setup, including helper executables,
# entitlements, and proper code signing. This snippet only demonstrates
# basic framework import and constant access.
try:
# Attempt to access a known constant
right_name = ServiceManagement.kSMRightBlessPrivilegedHelper
print(f"ServiceManagement constant kSMRightBlessPrivilegedHelper: {right_name}")
# Check for a typical function to ensure framework is loaded
if hasattr(ServiceManagement, 'SMJobCopyDictionary'):
print("ServiceManagement framework appears to be loaded and has SMJobCopyDictionary.")
except objc.nosuchmodule_error:
print("ServiceManagement framework not found or not importable. This library is macOS-only.")
except Exception as e:
print(f"An error occurred: {e}")