hammerspoon2-docs
    Preparing search index...

    Function on

    • Register a listener for AX events on a specific element

      Parameters

      • element: HSAXElement

        An HSAXElement to watch. Passing an application's element causes matching notifications to bubble up from anywhere in that application's hierarchy (e.g. AXWindowCreated for any window in the app, not just one); passing a specific descendant element scopes the notification to just that element

      • notification: string | string[]

        An event name, or an array of event names, to watch for with the same listener

      • listener: (notification: string, element: HSAXElement) => void

        A function called with the notification name and the accessibility element it applies to

      Returns void

      If a watcher can't be started, the Error says why, and when the Accessibility API reported an error its code property is that error's name: e.g. "kAXErrorAPIDisabled" (the application has turned the Accessibility API off, as Firefox in kiosk mode does, so retrying won't help), "kAXErrorNotificationUnsupported" (the element doesn't send that notification) or "kAXErrorCannotComplete" (the application didn't respond, e.g. because it is still starting up). When notification is an array, registration is all-or-nothing: if any one of them fails, none are left registered. Listeners are removed automatically when the watched element is destroyed, or when its application quits, so there is no need to call off in either case (doing so is harmless). A listener registered for uIElementDestroyed is still called for the element's destruction before it is removed.

      Throws an Error on failure; wrap calls in try/catch to handle it.