// Get the focused UI elementconst element = hs.ax.focusedElement();console.log(element.role, element.title);// Watch for window creation eventsconst app = hs.application.frontmost();hs.ax.addWatcher(app, "AXWindowCreated", (notification, element) => { console.log("New window:", element.title);}); Copy
// Get the focused UI elementconst element = hs.ax.focusedElement();console.log(element.role, element.title);// Watch for window creation eventsconst app = hs.application.frontmost();hs.ax.addWatcher(app, "AXWindowCreated", (notification, element) => { console.log("New window:", element.title);});
Note:* Requires accessibility permissions in System Preferences.
Accessibility API Module
Basic Usage
Note:* Requires accessibility permissions in System Preferences.