Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I detect when an external monitor is connected in linux?

I need to run various scripts to set up my workspace.

Is there some clever way to kick off a script when the monitor state has changed?

I'm using the Nvidia display driver.

share|improve this question
The hackish way would be to write a script that queries for changes in output in xrandr every couple seconds, and runs the script(s) if it notices a difference. – new123456 May 2 '11 at 20:01
Ideally you can tell udev to run a script. I don't expect that to work with nvidia drivers until KMS is supported, although I haven't tried.… – Andy May 21 '11 at 22:46

I was looking for the same answer :/
I'm using disper ( and gconftool to enable/disable my second monitor together with a second gnome-panel on it.
disper -l lists all connected monitors, so you could poll that as a last resort.

# only primary display
disper -s
gconftool-2 --type int --set  /apps/panel/toplevels/panel_1/screen -- -1

# dual display (nvidia twinview)
disper -e
gconftool-2 --type int --set  /apps/panel/toplevels/panel_1/screen 0
killall gnome-panel
share|improve this answer

There are a set of tools called read-edid that can parse extended display identification data (EDID). If your external monitor is actually detected by these tools, you might be able to periodically check for detection and use the output to start scripts, etc.

You didn't mention though whether you need to do this regardless of whether X was running.

share|improve this answer
Right, I only need it in X. I've got some other tools as well that'll detect the displays (like disper), but I was hoping to avoid having to write a daemon :) – Joernsn May 3 '11 at 8:15

You should use udev events... a possible rule might look like:

KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/ninette/.Xauthority", RUN+="/usr/local/bin/"


share|improve this answer

Given that, as of 270.18, the nVidia binary drivers still don't seem to implement modern XRandR, you may just have to go with new123456's suggestion to poll a tool like xrandr for changes in screen size.

On my system, I have yet to find a way to make nVidia properly announce to xrandr that I have two 1280x1024 monitors, rather than a single 2560x1024 one... which, as you can guess, makes fullscreen games center across both monitors when I forbid them from changing the resolution. (It mucks up my desktop stickies)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.