PyObjC PreferencePanes Framework Bindings
This library provides Python wrappers for Apple's `PreferencePanes.framework` on macOS, allowing Python applications to interact with or create System Preference panes. It's part of the larger PyObjC project, which offers Python bindings for many macOS frameworks. The current version is 12.1, with releases closely following macOS SDK updates and Python version support cycles.
Warnings
- breaking Apple officially deprecated `PreferencePanes.framework` in macOS 13 (Ventura) and removed it from the SDK in macOS 14 (Sonoma). This PyObjC binding will likely not function correctly or be buildable on recent macOS versions or with modern Xcode SDKs. Consider alternative frameworks like `Settings.framework` (macOS 13+) or `ServiceManagement.framework` for modern macOS system settings interaction.
- breaking PyObjC 12.0 dropped support for Python 3.9. PyObjC 11.0 dropped support for Python 3.8. Ensure your Python version meets the `pyobjc-core` requirements for the installed PyObjC version.
- gotcha Changes in PyObjC 10.3 affected how `__init__` and `__new__` work for Python subclasses of Objective-C classes. While partially fixed in 10.3.1 for user-implemented `__new__`, code relying on PyObjC's provided `__new__` might still not be able to use `__init__`.
- gotcha PyObjC 11.1 aligned its behavior with Clang's ARC documentation for initializer methods (those in the 'init' family). This means PyObjC now correctly models that 'init' methods steal a reference to `self` and return a new reference, potentially changing reference counting behavior for existing code that relied on the prior model.
- gotcha PyObjC does not fully support the experimental free-threading (PEP 703) introduced in Python 3.13. While experimental support was added in PyObjC 11.0, using PyObjC in a free-threaded Python environment might lead to unexpected behavior.
Install
-
pip install pyobjc-framework-preferencepanes
Imports
- NSPreferencePane
from PreferencePanes import NSPreferencePane
Quickstart
import sys
import platform
from Foundation import NSBundle
# Check macOS version as PreferencePanes.framework is deprecated
macos_version_tuple = tuple(map(int, platform.mac_ver()[0].split('.')))
if macos_version_tuple >= (13, 0):
print("Warning: PreferencePanes.framework is deprecated in macOS 13+ (Ventura) and removed from the SDK in macOS 14+ (Sonoma).")
print("This library's functionality is highly platform-dependent and may not work on recent macOS versions or with recent Xcode SDKs.")
print("For modern macOS, consider using the Settings.framework or ServiceManagement.framework if applicable.")
try:
from PreferencePanes import NSPreferencePane
print(f"Successfully imported NSPreferencePane: {NSPreferencePane}")
# Example: Trying to access a system bundle to demonstrate framework interaction
# Note: Creating a functional preference pane requires more complex setup (e.g., bundle structure, Info.plist)
bundle = NSBundle.mainBundle()
print(f"Main application bundle ID: {bundle.bundleIdentifier()}")
except ImportError:
print("Failed to import PreferencePanes. This usually means the framework is not available on your macOS version or SDK.")
print("Ensure you are running on macOS 12 (Monterey) or earlier for full PreferencePanes functionality, or have an older SDK installed.")
except Exception as e:
print(f"An unexpected error occurred: {e}")