Skip to main content

MacPaw Research

PyPI - Version

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.Image object of the app window.
  • im_seg: A PIL.Image object 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 😉

https://research.macpaw.com

Metadata

Release files for macapptree 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for macapptree 0.0.2
File Size Uploaded
macapptree-0.0.2.tar.gz 40.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for macapptree 0.0.2
File Interpreter ABI Platform
macapptree-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 40.3 MB

Release files / macapptree-0.0.2.tar.gz

Download URL macapptree-0.0.2.tar.gz
Size 40.3 MB
Tags Source
SHA-256 checksum
How to use checksums
c15aa9f5fe3c7218647381ac08e5e6644c69911273465f2a81cd597edc153323
BLAKE2b-256 checksum
How to use checksums
d7a7c14e6cdd552908a1d0aed93620a361eea632c34cb1ff8e80e4ccbd6d6e53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.15

Release files / macapptree-0.0.2-py3-none-any.whl

Download URL macapptree-0.0.2-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d19f2734b2f88e679c5929579d173dc6dcdff56d06d94243062d9624ebb7a5c3
BLAKE2b-256 checksum
How to use checksums
02ea38f94b075f846bbf35ebf56b18bcbb6352d1e4c52c26d3e3e1d41cbdbbed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.15

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page