sábado, 7 de fevereiro de 2009

Reach beyond Grasp: Hide and show panels with a keyboard shortcut in Ubuntu

Reach beyond Grasp: Hide and show panels with a keyboard shortcut in Ubuntu: "April 9, 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, paste it a file and save it as toggle.sh. A good way to place it will be /home/username/.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/unhide_delay' --type integer '0'
gconftool-2 --set '/apps/panel/toplevels/top_panel_screen0/auto_hide' --type bool 'false'
gconftool-2 --set '/apps/panel/toplevels/bottom_panel_screen0/unhide_delay' --type integer '0'
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/unhide_delay' --type integer '100000'
gconftool-2 --set '/apps/panel/toplevels/top_panel_screen0/auto_hide' --type bool 'true'
gconftool-2 --set '/apps/panel/toplevels/bottom_panel_screen0/unhide_delay' --type integer '100000'
gconftool-2 --set '/apps/panel/toplevels/bottom_panel_screen0/auto_hide' --type bool 'true'
fi


Make the script executable:

chmod +x ~/.toggle.sh


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

Then under /apps/metacity/global_keybindings, change the value of run_command_1 (if you used command_1 for the script) to controlF12 or any other key combination that you want. There, you are done! Now pressing the key combination will toggle the panels to hide or show. I have tested this with metacity and beryl on gnome and it works perfectly.

Edit: 10 April 2007 - Thanks to dzv (in the Ubuntu forums) for comments and the suggestion to change the unhide delay so that the panel stays hidden.





Powered by ScribeFire.
Posted by Raja at 6:07 PM
Labels: command line, Ubuntu
6 comments:

Anonymous said...

Hi, I would like to enable the same shortcut (hide/show), and tried your script. Using Ubuntu Feisty with the latest beryl release under XGL, it seems the gconf-editor keys the script edit have no effect on Gnome.

The script works nonetheless, since key values are edited in gconf. Do you know what the problem could be? Thanks :)
May 20, 2007 2:00 PM
Raja said...

I have the script working in Beryl. But you have to create the keybindings for the command in Beryl, not gnome.
So, open Beryl-manager and go to General Options -> Commands. Select command 0 and type the path to your script. Then go to General Options -> shortcuts -> Commands. Now you can bind command 0 to the key that you want to use.
Thanks for trying this out and hope this helps!
May 20, 2007 4:27 PM
Anonymous said...

Thank you. In fact I made a mistake in my statement, due to a confusion between Beryl and compiz. I've been running Beryl for a long time but someday it failed to launch and I returned to Metacity. Then, Feisty came out with a 'Click here and you'll get the 3D thing' option.

I did not realized it is using compiz and not all my beryl packages. Well, Beryl is going to merge/has merged (?) with compiz anyway, but it could explain why the script fails.

If I run beryl-manager, it basically crashes and Xgl complains. The gnome-compiz-manager has no shortcut/command section, but it could be gconf-editor then?

'Should clean my installation :)
Thank you for your help.
May 21, 2007 1:28 PM
Matt M said...

Thanks for the instructions and script.

Using gconf-editor was the final step for me --- setting the autohide size to zero.
May 8, 2008 7:47 AM
Offbrand said...

Ok, I got this working, but what are the chances we could get this to make the panels slide to the right like when using the panel hide buttons?
June 5, 2008 2:21 PM
Beni said...

Thank you for sharing this script. Works very well for me using Ubuntu Hardy.
September 2, 2008 10:25 AM"

Nenhum comentário: