PyObjC CoreServices Framework
pyobjc-framework-coreservices provides Python wrappers for Apple's CoreServices framework on macOS. It is part of the PyObjC project, a bidirectional bridge enabling Python scripts to interact with Objective-C libraries, including macOS Cocoa frameworks. The current version is 12.1 and it maintains an active, sustainable release cadence, typically aligning with macOS SDK updates and Python version support.
Warnings
- breaking PyObjC frequently drops support for older Python versions. PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped Python 3.8.
- breaking PyObjC 11.1 changed how initializer methods (methods in the `init` family) are modeled, now correctly reflecting that they 'steal' a reference to `self` and return a new one, as per clang's ARC documentation.
- gotcha Subclassing certain Cocoa string classes (e.g., `NSString` or `NSMutableString`) in Python can lead to crashes due to special handling within PyObjC.
- deprecated The `AVFAudio` package was moved from being merged into `AVFoundation` to being a separate top-level package in PyObjC 12.0.
- deprecated Several functions within the CoreServices framework, such as `LSInit` and `LSTerm`, are no longer available as they were removed in the macOS 10.7 SDK. The `IMServicePlugIn` framework bindings were also removed in PyObjC 10.0 due to deprecation and removal in macOS 14.
Install
-
pip install pyobjc-framework-coreservices
Imports
- CoreServices
import CoreServices
- Foundation
from Foundation import NSURL
Quickstart
import CoreServices
import Foundation
print(f"PyObjC CoreServices version: {CoreServices.__version__}")
# CoreServices is an umbrella framework. Its functionality is accessed via
# symbols from its sub-frameworks, such as LaunchServices.
try:
# Access a constant from LaunchServices, exposed via CoreServices
recent_items_list = CoreServices.kLSSharedFileListRecentDocumentItems
print(f"Successfully accessed kLSSharedFileListRecentDocumentItems: {recent_items_list}")
except AttributeError:
print("CoreServices module loaded, but kLSSharedFileListRecentDocumentItems not found or accessible. "
"This might indicate a version or SDK mismatch.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Example of creating a basic Foundation object, often used with CoreServices operations
file_url = Foundation.NSURL.fileURLWithPath_isDirectory_("/Applications/Safari.app", True)
print(f"Created Foundation.NSURL object: {file_url}")
print("Quickstart complete.")