How to listen for when an external display connects/disconnects?


Hey there! Is there a way to listen when an external display is connected or disconnected? Possibly via systemPreferences.subscribeNotification?

Thanks! :slight_smile:


Update after some digging:

It looks like I want to listen for NSApplicationDidChangeScreenParametersNotification events sent by the default notification center [NSNotificationCenter defaultCenter].

Is this possible with Electron? Yep :point_down:


The following does invoke the callback when I connect or disconnect an external display, however it doesn’t exactly tell me if the display was connected or disconnected… progress.

systemPreferences.subscribeLocalNotification('NSApplicationDidChangeScreenParametersNotification', (...args) => {
   // => [ 'NSApplicationDidChangeScreenParametersNotification', {} ]

I don’t suppose there’s a pure JS/Electron way to get the number of active screens?


Oh. Duh. Everything I’ve needed to do thusfar is covered in the native screen module.