alezzandro.com

bash scripting - VGA toggle switch

VGA port, really useful way to display through big Monitor or TV your tiny videos instead of watching them on your little notebook’s display :-)

Are you bored to have to restart X every time you want to connect your VGA cable?

Don’t you want to use gnome-display-etc-etc-manager to only configure a stupid VGA Monitor?

Don’t worry, you can use a little bash script (linked to some buttons on you panels), to manage your VGA connection.

I works like a switch, the script will enable the output choiced if this is disabled and viceversa it will disable the output if this is enabled.

But stop speaking (/writing) and watch it now:

vga.sh:

#!/bin/bash
#
# This script was created to manage an external output for notebook
#    The script only needs a bit of configuration to set the default output, mode, rate and extra options,
#    It works like a switch, the script will enable the output choiced if this is disabled and viceversa it will disable
#        the output if this is enabled.
#    It can be used on various acpi script linking it to your notebook’s fn+key.
#
# Made by: Alessandro Arrichiello <alezzandro@gmail.com>
#
# Configuration starts here:

output=“VGA”
mode=“1024x768”
rate=“60”
extra_options=“–right-of LVDS”
xrandr_cmd=“xrandr –output ”$output" –mode “$mode” –rate “$rate” “$extra_options

#
# END of Configuration

xrandr_output=`xrandr|grep $output`

if [ `echo $xrandr_output|grep -c disconnected` == "1” ]; then
echo “Cable for ”$output" not connected.“
else
if [ `echo $xrandr_output|grep -c connected` == "1” ]; then
if [ `echo $xrandr_output|grep -c $mode` == “1” ]; then
echo “Putting off: ”$output
xrandr –output $output –off
else
echo “Putting on: ”$output
`$xrandr_cmd`
fi

else
echo “Output not found check your configuration.”

fi
fi

Remember to set the right permissions (chmod +x vga.sh),

see you,