macOS accessibility parser
Project description
macapptree
macapptree is a Python package that extracts the accessibility tree of a macOS application's screen in JSON format. It also provides an option to capture screenshots of the application, including labeled bounding boxes with different colors representing various element types. This tool is useful for accessibility testing, UI automation, and visual debugging.
Features
- Accessibility Tree Extraction: Retrieve the accessibility hierarchy of a macOS application in JSON format.
- Screenshot Capture: Capture a cropped screenshot of the application window.
- Labeled Visual Output: Generate a segmented screenshot with bounding boxes highlighting UI elements, colored by their types.
Installation
To install macapptree, use pip:
pip install macapptree
Note: This package requires macOS and Python 3.8+.
Usage
The library provides two primary functions:
get_tree: Extracts the accessibility tree of a macOS app.get_tree_screenshot: Extracts the accessibility tree and generates screenshots.
Example
from macapptree import get_tree, get_tree_screenshot, get_app_bundle
# Get the app bundle identifier (for example: "com.apple.TextEdit")
bundle = get_app_bundle("TextEdit")
# Retrieve the accessibility tree, a cropped screenshot, and a segmented screenshot
tree, im, im_seg = get_tree_screenshot(bundle)
# `tree`: JSON-like structure of the accessibility elements
# `im`: Cropped screenshot of the application window
# `im_seg`: Labeled screenshot with bounding boxes indicating UI elements
Output
- tree: A Python dictionary representing the accessibility hierarchy.
- im: A cropped
PIL.Imageobject of the app window. - im_seg: A
PIL.Imageobject with bounding boxes drawn on top, colored based on the element type.
Example Tree Output
{
"id": "9d72c04ce9df11c8ab938ead88723de1",
"name": "Untitled",
"role": "AXWindow",
"description": null,
"role_description": "standard window",
"value": null,
"absolute_position": "214.00;119.00",
"position": "0.00;0.00",
"size": "586;476",
"enabled": false,
"bbox": [
0,
0,
586,
476
],
"visible_bbox": [
0,
0,
586,
476
],
"children": [
{
"id": "422f5e0df37aa872341d3b6a47faf320",
"name": null,
"role": "AXScrollArea",
"description": null,
"role_description": "scroll area",
"value": null,
"absolute_position": "214.00;175.00",
"position": "0.00;56.00",
"size": "586;420",
"enabled": false,
"bbox": [
0,
56,
586,
476
],
"visible_bbox": [
0,
56,
586,
476
],
"children": [
...
License
This project is licensed under the MIT License. See the LICENSE file for details.
MacPaw Research
Visit our site to learn more 😉
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file macapptree-0.0.2.tar.gz.
File metadata
- Download URL: macapptree-0.0.2.tar.gz
- Upload date:
- Size: 40.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c15aa9f5fe3c7218647381ac08e5e6644c69911273465f2a81cd597edc153323
|
|
| MD5 |
b9e6767020f65f7c0acf3507f0ef5815
|
|
| BLAKE2b-256 |
d7a7c14e6cdd552908a1d0aed93620a361eea632c34cb1ff8e80e4ccbd6d6e53
|
File details
Details for the file macapptree-0.0.2-py3-none-any.whl.
File metadata
- Download URL: macapptree-0.0.2-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d19f2734b2f88e679c5929579d173dc6dcdff56d06d94243062d9624ebb7a5c3
|
|
| MD5 |
243848dfe469c7b6a6b8116b63345fa9
|
|
| BLAKE2b-256 |
02ea38f94b075f846bbf35ebf56b18bcbb6352d1e4c52c26d3e3e1d41cbdbbed
|