{"id":5805,"library":"pyobjc-framework-coreservices","title":"PyObjC CoreServices Framework","description":"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.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","objective-c","cocoa","bindings","coreservices","launchservices","carboncore"],"install":[{"cmd":"pip install pyobjc-framework-coreservices","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"The core bridge between Python and Objective-C, required for all PyObjC framework wrappers.","package":"pyobjc-core"}],"imports":[{"note":"CoreServices is an umbrella framework; its sub-frameworks' symbols (e.g., LaunchServices, DictionaryServices) are typically accessed directly through the imported 'CoreServices' module.","symbol":"CoreServices","correct":"import CoreServices"},{"note":"Foundation is commonly used with PyObjC frameworks for basic object types like URLs, strings, and collections.","symbol":"Foundation","correct":"from Foundation import NSURL"}],"quickstart":{"code":"import CoreServices\nimport Foundation\n\nprint(f\"PyObjC CoreServices version: {CoreServices.__version__}\")\n\n# CoreServices is an umbrella framework. Its functionality is accessed via\n# symbols from its sub-frameworks, such as LaunchServices.\n\ntry:\n    # Access a constant from LaunchServices, exposed via CoreServices\n    recent_items_list = CoreServices.kLSSharedFileListRecentDocumentItems\n    print(f\"Successfully accessed kLSSharedFileListRecentDocumentItems: {recent_items_list}\")\nexcept AttributeError:\n    print(\"CoreServices module loaded, but kLSSharedFileListRecentDocumentItems not found or accessible. \"\n          \"This might indicate a version or SDK mismatch.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n\n# Example of creating a basic Foundation object, often used with CoreServices operations\nfile_url = Foundation.NSURL.fileURLWithPath_isDirectory_(\"/Applications/Safari.app\", True)\nprint(f\"Created Foundation.NSURL object: {file_url}\")\nprint(\"Quickstart complete.\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your Python environment is compatible with the PyObjC version you are installing. For PyObjC 12.x, Python >=3.10 is required. Always check `requires_python` on PyPI or the PyObjC changelog for specific version requirements.","message":"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.","severity":"breaking","affected_versions":"11.0, 12.0+"},{"fix":"Review code that interacts with object initialization, especially custom subclasses or factory methods, to ensure correct reference handling. Explicit memory management is rarely needed in Python, but understanding the underlying Objective-C semantics is crucial for correct behavior.","message":"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.","severity":"breaking","affected_versions":"11.1+"},{"fix":"Avoid subclassing `NSString` or `NSMutableString` directly in Python. If custom string-like behavior is needed, consider wrapping `NSString` instances or subclassing Python's `str` and converting when interacting with Objective-C APIs.","message":"Subclassing certain Cocoa string classes (e.g., `NSString` or `NSMutableString`) in Python can lead to crashes due to special handling within PyObjC.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update imports for `AVFAudio` functionality to `import AVFAudio` instead of accessing it through `AVFoundation`.","message":"The `AVFAudio` package was moved from being merged into `AVFoundation` to being a separate top-level package in PyObjC 12.0.","severity":"deprecated","affected_versions":"12.0+"},{"fix":"Avoid using deprecated CoreServices functions and frameworks. Refer to Apple's latest documentation for modern replacements and best practices.","message":"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.","severity":"deprecated","affected_versions":"10.0+"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}