I have a laptop running Ubuntu to which I connect an external monitor when I'm at the office. Usually this requires me to run "xrandr --auto" in order for the laptop to resize the display to match the external monitor. It would be nice if this could be done automatically, either triggered when the monitor is connected, but it would be enough to actually run "xrandr --auto" when the laptop wakes up from suspend/hibernate.
I created a script "/etc/pm/sleep.d/00xrandr.sh" containing the line
xrandr --auto
but this fails since the script does not have access to the X display.
Any ideas?