// Get the focused UI element constelement = 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. constapp = 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. constfield = 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.
Accessibility API Module
Basic Usage
Note:* Requires accessibility permissions in System Preferences.