hammerspoon2-docs
    Preparing search index...

    Namespace ax

    Accessibility API Module

    // Get the focused UI element
    const element = hs.ax.focusedElement();
    console.log(element.role, element.title);

    // Watch an application's element for window creation events. Notifications bubble up
    // from anywhere in the application's hierarchy, so this fires for every new window,
    // not just one specific window.
    const app = hs.application.frontmost();
    hs.ax.on(app.axElement(), hs.ax.notificationTypes.windowCreated, (notification, element) => {
    console.log("New window:", element.title);
    });

    // Watch a specific element (e.g. a text field found via findByRole) for value changes.
    // Watching a specific element scopes the notification to just that element, rather
    // than the whole application's hierarchy.
    const field = hs.ax.findByRole(hs.ax.roles.textField, app.axElement())[0];
    hs.ax.on(field, hs.ax.notificationTypes.valueChanged, (notification, element) => {
    console.log("Field changed:", element.value);
    });

    Note:* Requires accessibility permissions in System Preferences.

    Variables

    notificationTypes
    roles

    Functions

    applicationElement
    elementAtPoint
    findByRole
    findByTitle
    focusedElement
    off
    on
    once
    printHierarchy
    systemWideElement
    windowElement