{"id":5404,"library":"pyobjc-framework-applescriptkit","title":"PyObjC AppleScriptKit","description":"This library provides Python wrappers for the AppleScriptKit framework on macOS, allowing Python applications to embed, compile, and execute AppleScript code. It's part of the larger PyObjC project, which maintains a fairly active release cadence, typically releasing minor updates monthly/bi-monthly and major versions annually following macOS SDK updates. The current version is 12.1.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","pyobjc","applescript","automation","objective-c","cocoa"],"install":[{"cmd":"pip install pyobjc-framework-applescriptkit","lang":"bash","label":"Install the framework"}],"dependencies":[{"reason":"Provides the core bridge between Python and Objective-C, essential for all PyObjC framework bindings.","package":"pyobjc-core"},{"reason":"Many macOS frameworks, including AppleScriptKit, rely on fundamental classes from the Foundation framework (e.g., NSString, NSError), which are implicitly used.","package":"pyobjc-framework-Foundation","optional":true}],"imports":[{"note":"Framework symbols are typically imported directly at the top level after installation.","symbol":"AppleScriptKit","correct":"import AppleScriptKit"},{"note":"Specific classes within the framework can be imported directly if preferred.","symbol":"ASAppleScript","correct":"from AppleScriptKit import ASAppleScript"}],"quickstart":{"code":"import AppleScriptKit\nimport Foundation # For common Objective-C types like NSError\n\n# Define a simple AppleScript\nscript_source = '''\ndisplay dialog \"Hello from PyObjC AppleScriptKit!\"\nreturn \"Script executed successfully.\"\n'''\n\n# Create an ASAppleScript instance\n# Note: In PyObjC, None is used for 'nil' or 'NULL' in Objective-C\nerror_ptr = None # We'll pass None and check the returned tuple for errors\nscript = AppleScriptKit.ASAppleScript.alloc().initWithSource_error_(script_source, error_ptr)\n\nif script:\n    # Execute the script\n    result, error = script.executeAndReturnError_(error_ptr)\n    if error:\n        print(f\"Error executing script: {error.localizedDescription()}\")\n    elif result:\n        print(f\"Script result: {result.stringValue()}\")\n    else:\n        print(\"Script executed, no result or error reported.\")\nelse:\n    print(\"Failed to initialize ASAppleScript object.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize and execute a simple AppleScript string using the `AppleScriptKit` framework. It shows the typical pattern of allocating an Objective-C object, calling an initializer, and handling potential errors."},"warnings":[{"fix":"Upgrade to Python 3.10 or newer, or use an older PyObjC version (not recommended).","message":"Python 3.9 and earlier are no longer supported by recent PyObjC versions. PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped support for Python 3.8. Ensure your environment meets the `requires_python` spec (currently `>=3.10`).","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review custom Objective-C classes implemented in Python, especially `init` methods, for potential changes in reference counting behavior. Consult `clang`'s ARC documentation.","message":"PyObjC 11.1 aligned its behavior for initializer methods (e.g., `init` family methods) with `clang`'s Automatic Reference Counting (ARC) documentation. This change affects how references to `self` are handled and returned, potentially altering memory management in custom Objective-C classes implemented in Python.","severity":"breaking","affected_versions":">=11.1"},{"fix":"This library is not portable to other operating systems like Windows or Linux. Use platform-specific solutions for cross-platform applications.","message":"PyObjC (and therefore `pyobjc-framework-applescriptkit`) is exclusively for macOS. It relies heavily on macOS-specific Objective-C frameworks and the Cocoa bridge.","severity":"gotcha","affected_versions":"All"},{"fix":"If encountering issues with free-threading, consider running without `PYTHON_GIL=0` (i.e., with the GIL enabled) or sticking to an older Python version until free-threading support is more mature in PyObjC.","message":"PyObjC 11 introduced *experimental* support for free-threading (PEP 703) in Python 3.13. While progress has been made, users attempting to leverage free-threading might still encounter stability issues or unexpected behavior due to the complexity of the Objective-C runtime interacting with Python's new threading model.","severity":"gotcha","affected_versions":"11.0 - 12.x (with Python 3.13+)"},{"fix":"Consult the release notes for `pyobjc` and specific framework packages when upgrading major versions to identify removed or deprecated bindings.","message":"Older frameworks or bindings may be removed in major releases. For example, PyObjC 10.0 removed the `IMServicePlugIn` bindings as the framework was deprecated in macOS 10.13 and removed in macOS 14. Always check release notes for framework removals when upgrading major versions.","severity":"breaking","affected_versions":">=10.0"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}