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

All connected screens.


Declaration

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

Parameters

None

Return Value

An array of HSScreen objects

hs.screen.main

The screen that currently contains the focused window, or the screen with the keyboard focus if no window is focused.


Declaration

hs.screen.main() -> HSScreen

Parameters

None

Return Value

An HSScreen object or `null` if no main screen can be determined.

hs.screen.primary

The primary display — the one that contains the global menu bar.


Declaration

hs.screen.primary() -> HSScreen

Parameters

None

Return Value

An HSScreen object or `null` if no primary screen can be determined.