PyObjC InstantMessage Framework
PyObjC is a bridge between Python and Objective-C, enabling Python scripts to interact with and extend existing Objective-C class libraries, including Apple's Cocoa frameworks. The `pyobjc-framework-instantmessage` package (version 12.1) specifically provides Python bindings for the macOS InstantMessage framework. PyObjC generally coordinates its releases with macOS SDK updates, often leading to multiple major versions released per year.
Warnings
- breaking The `IMServicePlugIn` bindings are no longer available as the entire InstantMessage framework was deprecated in macOS 10.13 and removed in macOS 14. Any code relying on `IMServicePlugIn` will break on PyObjC versions 10.0 and later.
- deprecated The underlying Apple InstantMessage framework is deprecated and has been removed in macOS 14 (Sonoma). While `pyobjc-framework-instantmessage` bindings exist, the functionality they expose will be non-existent on modern macOS versions.
- breaking Support for Python 3.9 was dropped in PyObjC 12.0.
- breaking Support for Python 3.8 was dropped in PyObjC 11.0.
- gotcha Changes in `__init__` and `__new__` behavior when subclassing Objective-C classes in Python can lead to unexpected initialization issues. Specifically, if a user implements `__new__`, `__init__` can be used; otherwise, `__init__` cannot be used with the PyObjC-provided `__new__`.
- gotcha PyObjC 11.1 introduced changes in how initializer methods (methods in the 'init' family) handle reference counts, aligning with `clang`'s Automatic Reference Counting documentation. Initiator methods now correctly steal a reference to `self` and return a new reference, which might affect manual reference counting logic in older PyObjC code.
Install
-
pip install pyobjc-framework-instantmessage
Imports
- ABPresence
from InstantMessage import ABPresence
Quickstart
import InstantMessage
import objc
try:
# The InstantMessage framework itself is deprecated by Apple and removed in macOS 14.
# This example primarily demonstrates successful module import and attribute access,
# but functionality will be limited or absent on newer macOS versions.
if hasattr(InstantMessage, 'ABPresence'):
# Accessing a historically known class/protocol from the framework
ABPresence = InstantMessage.ABPresence
print(f"Successfully imported InstantMessage and found ABPresence: {ABPresence}")
print("Note: The InstantMessage framework is deprecated by Apple and its functionality may be limited or absent on recent macOS versions.")
else:
print("InstantMessage framework module loaded, but ABPresence class not found. "
"This is expected on macOS versions where the framework is removed (e.g., macOS 14+).")
except ImportError as e:
print(f"Error importing InstantMessage: {e}. "
"Ensure pyobjc-framework-instantmessage is installed and compatible with your macOS version.")
except Exception as e:
print(f"An unexpected error occurred: {e}")