PyObjC IntentsUI Framework
pyobjc-framework-intentsui provides Python wrappers for Apple's IntentsUI 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 release cadence, typically aligning with macOS SDK updates and Python version support.
Warnings
- breaking 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. Ensure your Python version is compatible with the PyObjC version you are installing.
- breaking PyObjC 11.1 changed how initializer methods (`init` family) are modeled, now correctly reflecting that they 'steal' a reference to `self` and return a new one, as per `clang`'s Automatic Reference Counting (ARC) documentation. This affects object lifecycle and reference counting.
- gotcha PyObjC is a macOS-specific library and will not install or run on other operating systems. The frameworks it wraps (like IntentsUI) are Apple-proprietary.
- gotcha Unlike Objective-C, where sending a message to `nil` (equivalent to Python `None`) is a no-op, attempting to call a method on a Python `None` object (which PyObjC translates from `nil`) will raise an `AttributeError`.
- gotcha PyObjC 10.3 introduced breaking changes in `__init__` and `__new__` handling for Objective-C classes, which was partially reverted in 10.3.1. While `__init__` can now be used when a user implements `__new__`, code relying on PyObjC's provided `__new__` still cannot use `__init__`. The recommended Pythonic instantiation is `MyClass(...)` (available since PyObjC 10.4) or the explicit `MyClass.alloc().init...()`.
- gotcha Although PyObjC 12.1 and later supports Python 3.13's experimental free-threading, the underlying Python feature itself is experimental. Earlier PyObjC versions (e.g., 10.3) did not support it.
Install
-
pip install pyobjc-framework-intentsui
Imports
- INUIAddVoiceShortcutViewController
from IntentsUI import INUIAddVoiceShortcutViewController
Quickstart
from IntentsUI import INUIAddVoiceShortcutViewController
from Foundation import NSObject
# IntentsUI classes like INUIAddVoiceShortcutViewController are typically used within
# a macOS application's Intents UI Extension, often involving XCode and Interface Builder.
# A simple standalone Python script usually cannot directly instantiate and display
# these UI elements without a full application context.
# This example primarily shows the import and a placeholder for where you might use it.
# For actual usage, refer to Apple's SiriKit documentation and PyObjC examples
# involving py2app and application development.
def create_intents_ui_controller():
# In a real application, you would instantiate and configure this controller.
# For example, to add a voice shortcut:
# controller = INUIAddVoiceShortcutViewController.alloc().initWithShortcut_(your_shortcut)
# Or, using the Pythonic instantiation (PyObjC 10.4+):
# controller = INUIAddVoiceShortcutViewController(shortcut=your_shortcut)
print(f"Successfully imported {INUIAddVoiceShortcutViewController.__name__}.")
print("IntentsUI classes require an application context, typically an Intents UI Extension.")
return None
if __name__ == "__main__":
create_intents_ui_controller()