API Reference
›
hs.screen
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
All connected screens.
Declaration
hs.screen.all() -> HSScreen[]
Returns
HSScreen[]
An array of HSScreen objects
Example
const screens = hs.screen.all()
screens.forEach(s => console.log(s.name))
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
Returns
HSScreen
An HSScreen object or `null` if no main screen can be determined.
Example
const main = hs.screen.main()
console.log(main && main.name)
The primary display — the one that contains the global menu bar.
Declaration
hs.screen.primary() -> HSScreen
Returns
HSScreen
An HSScreen object or `null` if no primary screen can be determined.
Example
const s = hs.screen.primary()
console.log(s && s.frame)