API Docs

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);

Display modes

const s = hs.screen.primary();
console.log(s.mode);
// → { width: 1440, height: 900, scale: 2, frequency: 60 }

s.setMode(1920, 1080, 1, 60);

Screenshots

const img = await hs.screen.main().snapshot();
img.saveToFile("/tmp/screen.png");

Types

This module provides the following types:

Properties

This module has no properties.

Methods

hs.screen.all() -> HSScreen[]

All connected screens.
hs.screen.all() -> HSScreen[]
HSScreen[]
An array of HSScreen objects
const screens = hs.screen.all()
screens.forEach(s => console.log(s.name))

hs.screen.main() -> HSScreen

The screen that currently contains the focused window, or the screen with the keyboard focus if no window is focused.
hs.screen.main() -> HSScreen
HSScreen
An HSScreen object or `null` if no main screen can be determined.
const main = hs.screen.main()
console.log(main && main.name)

hs.screen.primary() -> HSScreen

The primary display — the one that contains the global menu bar.
hs.screen.primary() -> HSScreen
HSScreen
An HSScreen object or `null` if no primary screen can be determined.
const s = hs.screen.primary()
console.log(s && s.frame)