{"id":6151,"library":"pyobjc-framework-osakit","title":"PyObjC OSAKit Framework Wrappers","description":"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.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macOS","PyObjC","Objective-C","OSAKit","automation","AppleScript"],"install":[{"cmd":"pip install pyobjc-framework-osakit","lang":"bash","label":"Install framework bindings"}],"dependencies":[{"reason":"This package provides the core bridging functionality between Python and Objective-C, upon which all PyObjC framework wrappers are built.","package":"pyobjc-core"}],"imports":[{"note":"The OSAKit framework bindings are directly imported as a top-level module named `OSAKit`.","symbol":"OSAKit","correct":"import OSAKit"},{"note":"Often required for basic Objective-C data types like `NSDictionary` used in error handling or other common operations.","symbol":"Foundation","correct":"import Foundation"}],"quickstart":{"code":"import OSAKit\nimport Foundation\nimport os\n\n# Source for a simple AppleScript\nscript_source = \"\"\"\ndisplay dialog \"Hello from PyObjC OSAKit!\" with title \"PyObjC\"\nreturn \"AppleScript executed successfully.\"\n\"\"\"\n\ntry:\n    # Create an OSAScript instance\n    script = OSAKit.OSAScript.alloc().initWithSource_(script_source)\n\n    # Prepare an error dictionary (Objective-C style error handling)\n    error = Foundation.NSDictionary.dictionary()\n\n    # Compile the script\n    compiled = script.compileAndReturnError_(error)\n\n    if not compiled:\n        print(f\"Error compiling script: {error}\")\n    else:\n        print(\"Script compiled successfully.\")\n        # Execute the script\n        result_desc, error_exec = script.executeAndReturnError_(error)\n        if error_exec:\n            print(f\"Error executing script: {error_exec}\")\n        else:\n            # OSADisplayResult is often an NSAppleEventDescriptor, use stringValue() to get Python string\n            print(f\"Script output: {result_desc.stringValue()}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or later.","message":"PyObjC 12.0 (and thus `pyobjc-framework-osakit` 12.0) dropped support for Python 3.9. Ensure your project uses Python 3.10 or newer.","severity":"breaking","affected_versions":">=12.0"},{"fix":"Upgrade your Python environment to 3.9 or later.","message":"PyObjC 11.0 dropped support for Python 3.8. Ensure your project uses Python 3.9 or newer.","severity":"breaking","affected_versions":">=11.0"},{"fix":"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)`.","message":"Objective-C method selectors with colons (e.g., `someMethod:withArgument:`) are translated to Python methods using underscores (e.g., `someMethod_withArgument_`). Remember to add a trailing underscore for single-argument methods.","severity":"gotcha","affected_versions":"all"},{"fix":"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.","message":"PyObjC 11.1 aligned the core bridge's behavior 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, which might affect reference counting in specific, complex scenarios.","severity":"gotcha","affected_versions":">=11.1"},{"fix":"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.","message":"In PyObjC 10.3, the ability to use `__init__` in Python classes that also implement `__new__` (or inherit from a class that implements it) was temporarily broken, but later reintroduced in 10.3.1. However, classes relying on `PyObjC`'s default `__new__` still cannot use `__init__`.","severity":"gotcha","affected_versions":">=10.3"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}