Automatically Switch Between Monitor Inputs

We geeks are lazy. Manually switching between monitor inputs can be a pain if you have to navigate the monitor’s menu to do so. If you’re lucky enough to have a monitor with a dedicated input switch button, constantly switching between inputs is a good way to break that switch on a cheap monitor.

Almost all monitors with multiple inputs will auto-switch to an input that has a signal if the current input’s signal goes away. This can be taken advantage of if you have the tools to force the monitor signal to turn off. Then switching inputs is easy.

  1. Make sure the computer you want to switch to is awake.
  2. Turn off the monitor signal on the computer you are currently using.

FOR WINDOWS: Download NirCmd and use nircmd.exe cmdwait 500 monitor off. For the most convenience, you can set a desktop shortcut and/or use the Shortcut Key property to call the command.

FOR LINUX: Copy this script and save it to /usr/bin/monitoroff. You can save it anywhere and name it anything, but /usr/bin will allow all users to run the command (chmod 755) and the name monitoroff coincides with the poweroff script on most Linux distros. (Credit.)

#!/bin/bash

###################################################
# Check if X is running or not, turn off monitor, #
# wait for a key press and turn it on again.      #
###################################################

grep_result_file=$PWD'/x_running'

# Check if X is running.
ps -e | grep -e "\bX\b" > $grep_result_file
ps -e | grep -e "\bxorg\b" >> $grep_result_file
ps -e | grep -e "\bxserver\b" >> $grep_result_file

## If you want to check result file, uncomment following lines.
#echo "===== $grep_result_file - begin ====="
#cat $grep_result_file
#echo "===== $grep_result_file -  end  ====="

if [ ! -s $grep_result_file ] || [[ $(tty) =~ tty ]] || [[ $(tty) =~ vc ]]; then
    echo 'Detected X not runnig or you are at console...'
    if [ $UID -ne 0 ]; then
        echo 'You need super user privileges to run this script at console.'
        echo 'Rerun as super user or start X and run from a terminal.'
        exit 0
    fi
    turn_off='vbetool dpms off'
    turn_on='vbetool dpms on'
else
    echo 'Detected X running...'
    turn_off='xset dpms force off'
fi

echo 'Turning off monitor...'
$turn_off

echo 'Waiting for a key press...'
read -n1 -s

echo 'Turning on monitor...'
$turn_on

rm $grep_result_file

echo 'Finished: monitor_off'