Simple Display Switcher Script

From ThinkWiki
Revision as of 17:18, 13 October 2009 by Brianfinley (Talk | contribs)
Jump to: navigation, search

Executive Summary

Here is a very simple script that with switch your Thinkpad from the built-in display to an external display. It automatically selects the preferred resolution and requires no options.

Install disper

This script relies on the program "disper", which provides a simple command to change between multiple displays. So, the first step is to install disper (http://willem.engen.nl/projects/disper/).

If you are running Ubuntu or Debian, you should be able to simply download and install the deb from here: http://ppa.launchpad.net/wvengen/ubuntu/pool/main/d/disper/

If you are running some other distribution, you may need to download and build/install from the tarball: http://ppa.launchpad.net/wvengen/ppa/ubuntu/pool/main/d/disper/


Install this Script

You can simply cut-and-paste the pre-formatted text below to install a copy of the script in /usr/local/bin:

cat <<EOF > /tmp/disper.simple_display_switcher
#!/bin/sh
#
# 2009.10.13 Brian Elliott Finley
# License: GPL v2
#
# This program uses disper to switch between the built-in and an
# external display on a notebook.  See
# http://willem.engen.nl/projects/disper/ for details on disper.

NOTEBOOK_DISPLAY="DFP-0"

disper --export 2>&1 | grep "metamode: $NOTEBOOK_DISPLAY"

if [ $? = 0 ]; then
    # enable the secondary display
    disper --secondary
else
    # enable the primary (notebook) display
    disper --single
fi
EOF

sudo install -m 755 -o root -g root /tmp/disper.simple_display_switcher /usr/local/bin/


Bind it to a Hot Key

Use your window or desktop manager to bind a hot-key to this script. You only need one hotkey, as it has no options. The script will detect which display is in use, and will activate the other one. Easy!

Comments

You can do other nifty things with disper too. See "man disper" for more information.