A native library for macOS to create virtual displays for your applications using Node.js. This library uses CoreGraphics and CoreDisplay APIs to provide an interface for creating and managing virtual displays on macOS. This library is used in Tab Display, a service that allows iPads and Android tablets to be used as portable monitors.
- Create and Destroy single virtual displays on macOS.
- Configurable display resolution and refresh rate.
- Create a virtual display by cloning the main display.
- Added option to select between Mirror and Extend display modes
- Support for multiple virtual displays.
- macOS 10.14 or later
- Node.js 12 or later
Use npm to install the library:
yarn add node-mac-virtual-displayTo create/destroy a virtual display:
const VirtualDisplay = require('node-mac-virtual-display')
const vdisplay = new VirtualDisplay()
// Clone primary display
vdisplay.cloneVirtualDisplay({
displayName: "Clone Display",
mirror: true
})
// OR
// To create a virtual display:
vdisplay.createVirtualDisplay({
width: 1920,
height: 1080,
frameRate: 60,
hiDPI: true,
displayName: "Virtual Display",
mirror: false
})
//To destroy a virtual display:
vdisplay.destroyVirtualDisplay()This library now automatically uses the Display Name (displayName) as the persistent identity key.
- Name-Based Persistence: When you create a display with
displayName: "My Monitor", it receives a consistent internal ID derived from that name. - Mac Memory: macOS will remember the window layout and resolution settings associated with that specific name.
- Simple Usage: Just use the same name next time, and your windows will be exactly where you left them.
If you keep the same displayName but drastically change the resolution or aspect ratio (e.g., 16:9 -> 4:3), macOS might get confused because it thinks it's the same monitor. If you need a "fresh" monitor profile, simply give it a new name (e.g. "Monitor V2").
Coffee fuels coding ☕️
