1.0.0 • Published 5 years ago
node-mac-displays v1.0.0
node-mac-displays
This native Node.js module allows you to enumerate over system display information.
API
Display Object
The Display object represents a physical display connected to the system. A
fake Display may exist on a headless system, or a Display may correspond to
a remote, virtual display.
Display objects take the following format:
idNumber - The display's unique identifier.nameString - The human-readable name of the display.supportedWindowDepthsNumber[] - The window depths supported by the display.rotationNumber - The screen rotation in clockwise degrees.scaleFactorNumber - Output device's pixel scale factor.isMonochromeBoolean - Whether or not the display is a monochrome display.colorSpaceObject - Representation of a custom color space.nameString - The localized name of the color space.componentCountNumber - The number of components, excluding alpha, the color space supports.
depthNumber - The number of bits per pixel.boundsObjectxNumber - The x coordinate of the origin of the rectangle.yNumber - The y coordinate of the origin of the rectangle.widthNumber - The width of the rectangle.heightNumber - The height of the rectangle.
workAreaObjectxNumber - The x coordinate of the origin of the rectangle.yNumber - The y coordinate of the origin of the rectangle.widthNumber - The width of the rectangle.heightNumber - The height of the rectangle.
internalBoolean -truefor an internal display andfalsefor an external display.isAsleepBoolean - Whether or not the display is sleeping.refreshRateNumber - Returns the refresh rate of the specified display.
displays.getAllDisplays()
Returns Array<Object> - Returns an array of display objects.
Example usage:
const displays = require('node-mac-displays')
const allDisplays = displays.getAllDisplays()
console.log(allDisplays[0])
/* Prints:
[
{
id: 69734406,
name: 'Built-in Retina Display',
refreshRate: 0,
supportedWindowDepths: [
264, 516, 520, 528,
544, 0, 0, 0
],
isAsleep: false,
isMonochrome: false,
colorSpace: { name: 'Color LCD', componentCount: 3 },
depth: 520,
scaleFactor: 2,
bounds: { x: 0, y: 0, width: 1680, height: 1050 },
workArea: { x: 0, y: 23, width: 1680, height: 932 },
rotation: 0,
internal: true
}
]
*/displays.getPrimaryDisplay()
Returns Object - the display containing the window with the keyboard focus.
Example Usage:
const displays = require('node-mac-displays')
const primary = displays.getPrimaryDisplay()
console.log(primary)
/* Prints:
{
id: 69734406,
name: 'Built-in Retina Display',
refreshRate: 0,
supportedWindowDepths: [
264, 516, 520, 528,
544, 0, 0, 0
],
isAsleep: false,
isMonochrome: false,
colorSpace: { name: 'Color LCD', componentCount: 3 },
depth: 520,
scaleFactor: 2,
bounds: { x: 0, y: 0, width: 1680, height: 1050 },
workArea: { x: 0, y: 23, width: 1680, height: 932 },
rotation: 0,
internal: true
}
*/displays.getDisplayByID(id)
idNumber - The device ID for the display.
Returns Object - the display with the specified device ID.
Example Usage:
const displays = require('node-mac-displays')
const display = displays.getDisplayByID(2077749241)
console.log(display)
/* Prints:
{
id: 69734406,
name: 'Built-in Retina Display',
refreshRate: 0,
supportedWindowDepths: [
264, 516, 520, 528,
544, 0, 0, 0
],
isAsleep: false,
isMonochrome: false,
colorSpace: { name: 'Color LCD', componentCount: 3 },
depth: 520,
scaleFactor: 2,
bounds: { x: 0, y: 0, width: 1680, height: 1050 },
workArea: { x: 0, y: 23, width: 1680, height: 932 },
rotation: 0,
internal: true
}
*/displays.mirror(enable, firstID[, secondID])
enableBoolean - Whether to enable or disable mirroring.firstIDNumber - The device ID for the primary display. If no second display ID is provided, the first display will default to the system's main display and the display corresponding to this ID will be set as the mirroring display.secondIDNumber (optional) - The device ID for the secondary display (which will mirror the first).
Example Usage:
const displays = require('node-mac-displays')
const [firstDisplay, secondDisplay] = displays.getAllDisplays()
// Set the second display to mirror the first.
displays.mirror(true, firstDisplay.id, secondDisplay.id)displays.screenshot(id, options)
idNumber - The device ID for the display.optionsObjecttypeString - The representation of the image. Can be 'jpeg', 'png', or 'tiff'. Defaults to 'jpeg'.boundsObjectxNumber - The x coordinate of the origin of the rectangle.yNumber - The y coordinate of the origin of the rectangle.widthNumber - The width of the rectangle.heightNumber - The height of the rectangle.
Returns Buffer - a Buffer representation of the desired display screenshot.
Takes a screenshot of the display with the specified id.
Example Usage:
const displays = require('node-mac-displays')
const fs = require('fs')
const path = require('path')
const { id } = displays.getPrimaryDisplay()
const ssPath = path.resolve(__dirname, 'screenshot.jpg')
const screenshotData = displays.screenshot(id, {
bounds: {
x: 100,
y: 500,
width: 200,
height: 200
}
})
// Write out JPEG image as screenshot.jpg in the current directory.
fs.writeFileSync(ssPath, screenshotData)1.0.0
5 years ago