I\'ve got an eeepc with an intel graphics. I\'d like to hook a script to the event of a monitor plugged via VGA. How to do that?
This other answer is on the right path: you want to listen to DRM events from udev.
I've implemented a Python script that runs some code when either USB devices or external displays are (un)plugged. I'm including below a minimal version of that script (untested):
#!/usr/bin/env python3
import pyudev
def udev_event_received(device):
... # Your code here!
context = pyudev.Context()
monitor_drm = pyudev.Monitor.from_netlink(context)
monitor_drm.filter_by(subsystem='drm')
observer_drm = pyudev.MonitorObserver(monitor_drm, callback=udev_event_received, daemon=False)
observer_drm.start()
# This will prevent the program from finishing:
observer_drm.join()
See also: