PyObjC PreferencePanes Framework Bindings

12.1 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

This quickstart attempts to import the main class from the `PreferencePanes` framework. It includes a critical warning about the framework's deprecation by Apple, which impacts its usability on modern macOS versions. It then demonstrates basic interaction by getting the main application bundle ID, a common pattern in macOS development.

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}")

view raw JSON →