Skip to main content

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.10+.


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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macapptree-0.0.1.tar.gz (35.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

macapptree-0.0.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file macapptree-0.0.1.tar.gz.

File metadata

  • Download URL: macapptree-0.0.1.tar.gz
  • Upload date:
  • Size: 35.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for macapptree-0.0.1.tar.gz
Algorithm Hash digest
SHA256 96fe17bf7f78612f9b61001d084eaa93816bcc7ae7650408ea3f339328c08f7b
MD5 81075429378e050060ad758d9c123a92
BLAKE2b-256 bf952ba41a5573eb194f30dc9ed427f0bb6a9063c68f30e7e032a91ff7888354

See more details on using hashes here.

File details

Details for the file macapptree-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: macapptree-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for macapptree-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7d986d66b2dd69243cd1980e72ceb05594fc8b78d477ae55a346d4799efc2da0
MD5 9ef5461a725e13b5245f2f362fcbe4d2
BLAKE2b-256 9619b3396bae0fc623ec7bf83f949693405678c18a527b637e62ff6da2fab0ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page