Skip to content

Instantly share code, notes, and snippets.

@CerebralMastication
Created March 4, 2011 15:42
Show Gist options
  • Save CerebralMastication/854838 to your computer and use it in GitHub Desktop.
Save CerebralMastication/854838 to your computer and use it in GitHub Desktop.
script for detecting monitors in Ubuntu
#!/bin/sh
#
# Detect displays and move panels to the primary display
#
#15 second pause
sleep 15
PYTHON=python2.6
DISPER=/usr/bin/disper
# disper command will detect and configure monitors
$PYTHON $DISPER --displays=auto -e -t left
# parse output from disper tool how many displays we have attached
# disper prints 2 lines per displer
lines=`$PYTHON $DISPER -l|wc -l`
display_count=$((lines / 2))
echo $display_count
echo "Detected display count:" $display_count
# Make sure that we move panels to the correct display based
# on the display count
if [ $display_count = 1 ] ; then
echo "Moving panels to the internal LCD display"
gconftool-2 \
--set "/apps/panel/toplevels/bottom_panel_screen0/monitor" \
--type integer "0"
gconftool-2 \
--set "/apps/panel/toplevels/top_panel_screen0/monitor" \
--type integer "0"
sleep 5
pkill gnome-panel
else
echo "Moving panels to the external display"
gconftool-2 \
--set "/apps/panel/toplevels/top_panel_screen0/monitor" \
--type integer "1"
gconftool-2 \
--set "/apps/panel/toplevels/bottom_panel_screen0/monitor" \
--type integer "1"
sleep 5
pkill gnome-panel
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment