What a wonderful day it is, sir
It’s been a while since I wrote something, but I liked to share this with you all. I bought a new Dell Studio 1558 and all the fn-keys were working except the one to switch the displays…
I enjoy switching between dual-screen, using only my external 22″ or using only my laptop, when I’m on the road. So I was looking for a workaround.
This laptop, is my first machine with Ubuntu that uses an ATI graphics chip, so this was all quite new to me. But I have to say; I’m very very pleased with it.
Ok, so what do you have to do to get things working?
1. Create the script
Create the script, I called it toggleDisplay.sh and this is how it looks in my case:
#!/bin/bash # Script to toggle display configuration on Dell Studio 1558 # author: Ruben Verhack config="/tmp/display.conf" current=`cat $config` # Check if config exists if [ ! -a $config ] then # Empty file executes default touch $config; fi # Check if CRT2 is connected if xrandr -q | grep "CRT2 connected" then # Toggle between states case "$current" in '') # default xrandr --output LVDS --auto --output CRT2 --left-of LVDS --output CRT2 --auto echo "dual" > $config ;; 'dual') # was dual, now external only xrandr --output LVDS --off --output CRT2 --auto echo "external" > $config ;; 'external') # was external, now laptop only xrandr --output LVDS --auto --output CRT2 --off echo "laptop" > $config ;; 'laptop') # was laptop, now both xrandr --output LVDS --auto --output CRT2 --left-of LVDS --output CRT2 --auto echo "dual" > $config ;; esac else xrandr --output LVDS --auto fi
This toggles your displays from dual screen to external only to laptop only, and from there to dual screen again. Note that my monitors were called LVDS and CRT2, you can easily check how your monitors are called by executing:
xrandr -q
It’s pretty easy, huh?
2. Bind the key to the script
Make sure you given the script rights to be executed, let’s assume you’ve put the shell script in your home-folder.
chmod +x ~/toggleDisplay.sh
Next launch Gnome Keybinding by launching System > Preferences > Keybindings .
Add a custom action:
- Name: Toggle Displays
- Action: sh ~/toggleDisplay.sh
Select it, click on the shortcut and press the key you want to bind to this action and presto!
I hope this helped someone!









Hi,
I have a Dell Vostro 1520 with nvidia. The script works with it?
Pedro
3 Aug 10 at 03:51
@Pedro
Frankly, I have no idea…
ruben
27 Oct 10 at 16:36
It seems that I lost some comments, I’m putting them here:
——————————–
Ro:
Great help!
Was looking for a solution some for time.
Some comments:
- The “if [ ! -a $config ]” should be “if ! [ -a $config ]”
- I would use the file extension “.bash” instead of “.sh”
- The action should be “bash /home/xxx/toggleDisplay.bash”:
– The bash at the start is not important, can also be sh
– The expansion to /home/ is important, didnĀ“t work without
————————————————————-
aap:
Thanks, that’s exactly what I was looking for. The only question is why Ubuntu doesn’t come with functionality this out-of-the-box.
————————————————————-
Thx!
ruben
27 Oct 10 at 16:37
Thanks, work with a little modification on my machine (change name of displays)
Hendra
10 May 11 at 12:40
Thanks! That’s well explained, and it worked perfectly.
Tim
22 Jul 11 at 02:44
Great! It works fine at once! Thank you
Davide Aimi
25 Jul 11 at 22:02