3

I'm writing a script in which I need to switch between two displays, but I can't find a way to get the information about the current active output.

Pretty much like this:

if Display0 is off and Display1 is on
     turn off Display1
     turn on Display0
else if Display1 is off and Display0 is on
     turn off Display0
     turn on Display1

The piece I'm missing is the first line: how do I know which display is currently active?

Note: xrandr -q doesn't help because it always print that both displays are "connected" regardless of whether the output is directed on Display0 or Display1, not sure if this is a bug.

  • Can you give the output of echo $DISPLAY? when both display connected and also when 1th is connected and then when 2th connected. (each result in separate line). thank yoou – αғsнιη Dec 27 '14 at 11:33
  • @KasiyA echo $DISPLAY returns :0 regardless of the connected display – oidualc Dec 27 '14 at 11:49
  • It that the same result when you connect both of the displays? – αғsнιη Dec 27 '14 at 11:54
  • What does DISPLAY=:0 xrandr | grep primary say? – muru Dec 27 '14 at 12:01
  • @KasiyA yes, same result when both displays are connected. As far as I can see the DISPLAY variable isn't affected at all by the disposition – oidualc Dec 27 '14 at 12:03
0
xrandr | awk '/\ connected/ && /[[:digit:]]x[[:digit:]].*+/{print $1}'

here is the command to find which monitors are on, which is your original question.

Also I wrote the script to switch between monitors: Swap between monitor display modes using shortcut

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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