PyObjC is a bridge between Python and the Objective-C runtime, enabling Python scripts to interact with Apple's Cocoa frameworks. This specific package, `pyobjc-framework-osakit`, provides Python bindings for the OSAKit framework on macOS, allowing for the creation, compilation, and execution of AppleScripts and other scripting components. The current version is 12.1. Releases are frequent, often correlating with new macOS SDKs and Python version support changes.
pip install pyobjc-framework-osakitVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `pyobjc-framework-osakit` to programmatically compile and execute a simple AppleScript. It initializes an `OSAScript` object with source code, attempts to compile it, and if successful, executes it. Error handling follows the common PyObjC pattern using `NSDictionary` to capture Objective-C errors.
Upgrade your Python environment to 3.10 or later.
Upgrade your Python environment to 3.9 or later.
When calling Objective-C methods, replace colons in the selector with underscores and append an underscore if the original selector ends with one (i.e., takes an argument). Example: `alloc().initWithSource_(source)`.
Review code that interacts closely with Objective-C object lifecycle, especially `alloc` and `init` methods, to ensure correct reference management under the new ARC model.
If implementing custom `__new__` methods in PyObjC-bridged classes, be mindful of how `__init__` is called. For classes using PyObjC's `__new__`, `__init__` is generally not supported for object creation.