February 24, 2007

Hide and show panels with a keyboard shortcut in Ubuntu

I usually keep the default top and bottom panels in gnome, but especially on my laptop, place great value on the screen estate that I can get by hiding them. The usual way I do this is by using autohide and then setting the hidden size to 0 or 1. Mostly I dont need the panels because I can launch applications with Alt-F2 or with shortcuts. But when I need to access something from the panel, I have to mouse over the hidden panel to bring it up. The other minor irritation is that the panel may spring out when you dont really want it if your mouse wanders close to it.



In a recent post in the Ubuntu forums, it was suggested that it would be nice to set up a keyboard shortcut to show the panels when needed. Since it is easy to access the gconf-editor from the command line, it was easy to write a script to toggle the hide status of the panel. Here is a short how-to if someone is interested.



Copy this script and save it as "toggle.sh". A good location to keep it would be /home/<username>/.toggle.sh.  Make the file executable :



chmod  +x  ~/.toggle.sh



#!/bin/bash



#find the current state of the panels

state=`gconftool-2 --get "/apps/panel/toplevels/top_panel_screen0/auto_hide"`



#if autohide on, turn it off

if [ $state = "true" ]; then

    gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "false"

    gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"

fi



#if autohide off, turn it on

if [ $state = "false" ]; then

    gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/auto_hide" --type bool "true"

    gconftool-2 --set "/apps/panel/toplevels/bottom_panel_screen0/auto_hide" --type bool "false"

fi



Open gconf-editor now, and in /apps/metacity/keybinding_commands, change the value of command_1 (or any other command which is unused) to /home/<username>/.toggle.sh.

 

Then go to /apps/metacity/global_keybindings and change the value of run_command_1 (if you mapped the script to command_1) to <Control>F12 or any other key combination you choose. Close gconf-editor and try it out ! I tested this with both metacity and beryl and it works perfectly.

2 comments:

Anonymous said...

i use a modification of this using a compiz key binding. It works great except sometimes (maybe just when i come back from suspend) the panel doesn't actually hide. the icons on my desktop shift like it is hidden and my maximized screens overlap it/ hit the far side of the screen, but the panel is still there. any ideas about this?

Anonymous said...

You can also do this, http://jambelnet.blogspot.com/2009/08/showhide-gnome-panels-using-gconftool-2.html