Auto-detect monitor unplug

I know of no clean way to detect an unplugged screen, so I figured I'd force re-detection with a cron job.
To detect the monitors I'm using disper, you can get it from the Wheezy and Sid repositories.
Let's open up our crontab.
crontab -e
If you're doing this for other users too, you may use
sudo crontab -eu <username> 
Now add a new entry:
0-59 * * * * DISPLAY=:0.0 disper -ld auto > /dev/null
This will automatically detect (-d auto) and list (-l) all monitors every minute.
Of course, you can also use xrandr:
0-59 * * * * DISPLAY=:0.0 xrandr --auto > /dev/null
Both of these commands will adjust your desktop automatically, which will do just fine for most users. The > /dev/null at the end discards all standard output instead of sending you emails. You will still receive error messages.
Thanks to bammes for pointing me in the right direction regarding the display. 

No comments:

Post a Comment