macapptree
A Python package that extracts the accessibility tree of macOS application windows as JSON, with an option to capture matching screenshots that highlight each UI element by type, for accessibility testing, UI automation and visual debugging.
macapptree retrieves the accessibility hierarchy of one or more macOS applications as JSON, and can additionally capture a cropped screenshot of an application window alongside a labeled version that draws colored bounding boxes around UI elements by type. It can also capture the Dock and menu bar, or every currently visible running app at once.
The library exposes two main functions, one for extracting the tree alone and one that also produces the screenshots, and the same functionality is available from the command line for capturing multiple named applications or every open application in one pass. It installs through pip, requires macOS and Python 3.8 or newer, and is released under the MIT license.