{"id":5022,"library":"pyobjc-framework-applicationservices","title":"PyObjC ApplicationServices Framework","description":"PyObjC provides Python bindings for Objective-C frameworks on macOS, enabling Python developers to interact with Apple's system APIs. `pyobjc-framework-applicationservices` offers wrappers for the ApplicationServices umbrella framework, which includes various core services like CoreGraphics, CoreText, and HIServices. The library is currently at version 12.1 and maintains an active release cadence, typically aligning with macOS and Python version updates.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","cocoa","frameworks","apple","gui","bridge","coregraphics","applicationservices"],"install":[{"cmd":"pip install pyobjc-framework-applicationservices","lang":"bash","label":"Install specific framework"},{"cmd":"pip install 'pyobjc[allbindings]'","lang":"bash","label":"Install PyObjC with all framework bindings"}],"dependencies":[{"reason":"Provides the core bridge between Python and Objective-C, essential for all PyObjC framework wrappers.","package":"pyobjc-core","optional":false}],"imports":[{"note":"Sub-frameworks bundled under ApplicationServices, such as CoreGraphics, are accessible directly as modules within the ApplicationServices package.","symbol":"CoreGraphics","correct":"from ApplicationServices import CoreGraphics"},{"note":"Constants and functions from sub-frameworks like CoreGraphics are exposed as attributes of their respective modules imported from ApplicationServices.","symbol":"kCGColorSpaceGenericRGB","correct":"from ApplicationServices import CoreGraphics; colorSpace = CoreGraphics.CGColorSpaceCreateDeviceRGB()"}],"quickstart":{"code":"import ApplicationServices\nimport os\n\ndef get_display_bounds():\n    \"\"\"\n    Retrieves the bounds of the primary display using CoreGraphics\n    from ApplicationServices.\n    \"\"\"\n    # Access CoreGraphics functions via ApplicationServices.CoreGraphics\n    main_display_id = ApplicationServices.CoreGraphics.CGMainDisplayID()\n    bounds = ApplicationServices.CoreGraphics.CGDisplayBounds(main_display_id)\n\n    # PyObjC automatically bridges CGRect to a dictionary-like object\n    x = bounds.origin.x\n    y = bounds.origin.y\n    width = bounds.size.width\n    height = bounds.size.height\n\n    print(f\"Primary display bounds: x={x}, y={y}, width={width}, height={height}\")\n    return {\"x\": x, \"y\": y, \"width\": width, \"height\": height}\n\nif __name__ == '__main__':\n    # This example does not require an active NSApplication runloop\n    # for just getting display bounds.\n    display_info = get_display_bounds()\n    assert display_info['width'] > 0 and display_info['height'] > 0\n    print(\"Successfully retrieved display information.\")","lang":"python","description":"This quickstart demonstrates how to access a sub-framework (CoreGraphics) within ApplicationServices to retrieve the primary display's bounds. It highlights the direct import pattern and attribute access for framework elements."},"warnings":[{"fix":"Ensure your Python environment meets the `requires_python` specification (>=3.10 for PyObjC 12.1) before upgrading PyObjC.","message":"PyObjC frequently drops support for older Python versions. PyObjC 12.0 dropped Python 3.9, and PyObjC 11.0 dropped Python 3.8. Always check the `requires_python` metadata or release notes to ensure compatibility with your Python environment.","severity":"breaking","affected_versions":"11.0, 12.0+"},{"fix":"Review custom `init` implementations in Python subclasses of Objective-C objects. PyObjC 10.3 introduced a Pythonic `Class(...)` instantiation pattern that is generally safer.","message":"PyObjC 11.1 aligned its core bridge with `clang`'s Automatic Reference Counting (ARC) documentation for initializer methods. Methods in the 'init' family now correctly steal a reference to `self` and return a new reference. This changed behavior for `[NSObject alloc]` proxies and can affect custom `init` implementations, potentially leading to crashes if old patterns are used.","severity":"breaking","affected_versions":"11.1+"},{"fix":"When subclassing Objective-C classes, implement Objective-C style `init` methods (e.g., `initWithFoo_:`). If overriding `__new__` in a Python subclass, be aware of the interaction with `__init__` and refer to PyObjC documentation on object instantiation.","message":"Version 10.3 initially broke `__init__` usage for Python subclasses of Objective-C classes, particularly when a user implemented `__new__` or when relying on PyObjC's `__new__` behavior. This was partially reverted in 10.3.1 to reintroduce `__init__` support when a user implements `__new__`.","severity":"gotcha","affected_versions":"10.3, 10.3.1"},{"fix":"Exercise caution and implement explicit locking when accessing or modifying Objective-C objects and Cocoa APIs concurrently from multiple threads, especially with GUI elements or mutable collections.","message":"PyObjC 11.0 introduced experimental support for free-threading (PEP 703) with Python 3.13+. While PyObjC protects its own implementation, Apple's frameworks are not necessarily thread-safe (e.g., `NSMutableArray` for concurrent updates, non-atomic properties, GUI classes on non-main threads).","severity":"gotcha","affected_versions":"11.0+ with Python 3.13+"},{"fix":"Do not subclass `NSString` or `NSMutableString` in Python. If custom string behavior is needed, wrap an existing `NSString` or use Python's built-in string types.","message":"`NSString` and `NSMutableString` are marked as 'final' in PyObjC versions 11.1 and later. Attempting to subclass these in Python will result in crashes due to special handling within PyObjC.","severity":"gotcha","affected_versions":"11.1+"},{"fix":"Ensure Xcode or the Command Line Tools are installed via `xcode-select --install` before attempting installation, particularly if encountering compilation errors.","message":"Installing PyObjC (especially from source or if binary wheels aren't suitable) requires Xcode or the Command Line Tools to be installed on macOS, including a compatible SDK for the target macOS version.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}