PyObjC Framework MediaAccessibility
pyobjc-framework-mediaaccessibility provides Python bindings for Apple's MediaAccessibility framework on macOS. It allows Python developers to interact with system-wide media accessibility settings, such as closed captions and audio descriptions. The library is part of the larger PyObjC project, which regularly releases updates, typically aligning with new macOS SDKs and Python versions. The current version is 12.1.
Warnings
- breaking PyObjC 12.0 and later (including 12.1) officially dropped support for Python 3.9. Attempting to install or use pyobjc-framework-mediaaccessibility==12.x on Python 3.9 will result in errors.
- breaking PyObjC 10.3 introduced changes to `__init__` and `__new__` interaction, where `__init__` could not be used if PyObjC provided `__new__`. Version 10.3.1 partially reverted this, reintroducing `__init__` support if the user provides their own `__new__` implementation. If you rely on custom `__init__` methods in Python subclasses of Objective-C classes, this might break your code, especially if upgrading from pre-10.3 versions.
- gotcha PyObjC supports experimental free-threading (PEP 703) introduced in Python 3.13. While PyObjC itself strives for thread-safety, Apple's underlying Objective-C frameworks (including MediaAccessibility) are not guaranteed to be thread-safe. Concurrent access to Objective-C objects or APIs from multiple Python threads without proper locking can lead to crashes or undefined behavior.
- gotcha All `pyobjc-framework-*` packages, including `pyobjc-framework-mediaaccessibility`, require `pyobjc-core` to function. Installing only a specific framework package without `pyobjc` (the meta-package) or `pyobjc-core` explicitly can lead to `ImportError` or other runtime failures.
- gotcha PyObjC is a macOS-specific library and will not function on other operating systems like Linux or Windows. Its entire purpose is to bridge Python with Apple's Objective-C frameworks.
- gotcha PyObjC framework wrappers generally do not include extensive Python-specific docstrings for the wrapped Objective-C APIs. Users are expected to consult Apple's official MediaAccessibility framework documentation for details on classes, methods, constants, and function usage.
Install
-
pip install pyobjc-framework-mediaaccessibility
Imports
- MediaAccessibility
import MediaAccessibility
Quickstart
import MediaAccessibility
# Get the currently selected caption language for the user domain
selected_language = MediaAccessibility.MACaptionAppearanceCopySelectedLanguage(
MediaAccessibility.kMACaptionAppearanceDomainUser
)
if selected_language:
print(f"Selected caption language (user domain): {selected_language}")
else:
print("No selected caption language found for the user domain.")
# Note: MACaptionAppearanceCopySelectedLanguage returns a CFStringRef, which PyObjC
# automatically bridges to a Python string. Memory management (release) is typically
# handled by PyObjC for bridged objects.