PyObjC CoreServices Framework

12.1 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

This quickstart demonstrates successfully importing the CoreServices module and accessing a symbolic constant from its LaunchServices sub-framework. It also includes a basic Foundation.NSURL object creation, a common pattern when working with macOS frameworks.

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

view raw JSON →