Inspect and control the displays attached to the system.
Obtaining screens
const all = hs.screen.all(); // [HSScreen, ...]
const main = hs.screen.main(); // screen containing the focused window
const primary = hs.screen.primary(); // screen with the global menu bar
Navigation
const right = hs.screen.main().toEast();
if (right) console.log("Screen to the right:", right.name);
Registers a listener that fires whenever the display configuration changes —
monitors connected/disconnected, resolution or arrangement changed, or the
menu bar moved to a different display.
The listener receives no arguments; call `all()`/`main()`/`primary()` inside
the callback to inspect the new configuration.
The OS notification subscription starts lazily on the first listener and
is released automatically when the last listener is removed.
Declaration
hs.screen.addWatcher(listener) -> None
Parameters
Name
Type
Description
listener
function
A function called with no arguments when the display configuration changes.