3

I have my monitor hooked up to computer A via DVI and to computer B via VGA. If I start PC A first and PC B last, the monitor displays PC A's signal.

Is there an easy way to change between the two signals via the command line such that the monitor displays the signal of the desired PC without me having to unplug the monitor?

3
  • 1
    Will your TV switch if you make the screensaver 'sleep' the display? Jul 19, 2016 at 9:24
  • Yes it does. So that's one way that would work but perhaps there's still a better one...
    – AlphaOmega
    Jul 19, 2016 at 9:56
  • I have seen projectors that allow USB and/or network control for input switching, but I've never seen a computer monitor with that feature. That means, as far as I can tell, that the sleep hack is the only option.
    – Moshe Katz
    Jul 19, 2016 at 14:31

2 Answers 2

7

If making the screen sleep works, then almost certainly the toggle- script below will work:

#!/bin/bash
# --- set your monitor below
monitor=VGA-0
# ---
if [ -z "$(xrandr | grep $monitor | grep +)" ]; then
  xrandr --output $monitor --auto
else
  xrandr --output $monitor --off
fi

The script toggles on/off a monitor, to be set in the head of the script:

# --- set your monitor below
monitor=VGA-0
# ---

How to use

  1. Copy the script into an empty file, save it as screentoggle.sh
  2. In the head of the script, set the monitor, like in the example. Use xrandr to find the name of your monitor
  3. Add the script to a shortut key: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    sh /path/to/screentoggle.sh
    

Now if you toggle the screen off on one computer, it will be available on the other.

Note

You probably need to add (and run) the shortcut on both computers, since the screen will only switch if the screen is set to --auto on at least one computer.

2

How about xset dpms force standby which just does the obvious, turns the display off (there are options of on, off, standby, suspend).
You can simply use the reverse xset dpms force on to resume; you could have a script linking via ssh to turn the other PC's display on/off as required:
xset dpms force standby; ssh other_pc xset dpms force on

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .