How to toggle desktop icons on and off

If you like me like to have icons on desktop but sometimes need to just hide everything to better concentrate on what you’re doing you may like this little bash script I came out with. (warning: this post applies only to gnome)

Istructions

Verify you have gconf2 installed. Do that with: sudo apt-get install gconf2.

You need a folder where to store this script (along with other scripts maybe), so make one or just use your home folder. So, open this folder and create an empty file. Call it toggle_desktop.sh or something like that. Open it with gedit and paste this text in the file.

#!/bin/bash

if [ $(gconftool-2  --get /apps/nautilus/preferences/show_desktop) == "true"  ]; then
	echo "disabling desktop"
	gconftool-2   --type boolean --set /apps/nautilus/preferences/show_desktop "false"
else
	echo "enabling desktop"
	gconftool-2   --type boolean --set /apps/nautilus/preferences/show_desktop "true"
fi;

# nautilus may crash ( !#£%$$@à###!!!! )

echo "checking if nautilus is still up"
sleep 1
if [ $( ps xa | grep nautilus | grep -v grep ) -z ]; then
	echo "nautilus is not up or crashed. Restarting nautilus"
	nautilus -n &
	echo "everything done."
else
	echo "all good - finishing job"
fi;

Done ? Save it and close gedit. Right click it, choose properties, then permissions and mark the file as executable.

Now all you need to do is double click it to hide or show your desktop icons. You may want to drag the file to your panel to access it more easily:

Note: There are a few shortcomings.

  1. The first is that when you hide your icons, you cannot anymore right click on the desktop. Nor changing desktop background works, it will get applied when you show your icons again.
  2. The second thing is that while hiding your desktop is quite fast showing it again may take 1 second or two and your window manager may become unresponsive in the meantime.
  3. Third thing to keep in mind: sometimes nautilus just crashes. I’ve included a quick check in the script to restart it. Nautilus crashing means it could just wipe (close) away all you’re opened file browsers. In my tests I’ve never one file browser wiped away, but it could happen. Nothing dangerous, only annoying.

This seems like a great time to subscribe my RSS !

3 responses to “How to toggle desktop icons on and off”

  1. joe

    Did just like you said and nothing. Does it requre sudo to run?

    Hardy Heron
    Compiz turned off and on
    Gnome of course cause KDE is the devil

  2. Stefano Forenza

    @Joe: no, it doesn’t require sudo and shuold not be run with sudo (because that would change the settings of the root user, not your user’s).

    Check if you have gconf2 installed. sudo apt-get install gconf2.

    Otherwise, I’d suggest taking a look at the script output to understand where it fails

  3. g33k

    gconftool-2 –type boolean –set /apps/nautilus/preferences/show_desktop “false”
    Not only hides desktop but also disables right click action on desktop.

Leave a Reply

Don’t forget to Subscribe

Bills

Latest Activity

Posts

  • What is Google ChromeOS, I mean really ?
    All this fuss about Google ChromeOS. Is it a threat to Microsoft ? Is it a threat to the Ubuntu ? (funny nobody wonders if that’s Read More
  • Well said Carla !
    Carla has something to say ’bout the cloud, and I agree 100% with her. Share it !
  • No more Gimp for you little Joe
    When I first posted about the matter, most people’s reaction was LOL. The we thought it was just a random proposal, never going to be Read More
  • Custom iTunes page generator
    Who never dreamed to have his personal Apple website page, like this guy ? Now you can ! UPDATE : they just fixed the page, Read More
  • Fedora's new little friend
    Straight from the release notes of the recently released Fedora 12: Gnote is installed by default in GNOME for this release replacing Tomboy. Gnote is a port Read More