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

Bills

Don’t forget to Subscribe

Latest Activity

Posts

  • Google this is ridiculous
    Google you’re doing it wrong. Very wrong. This is utterly ridiculous. It’s a screenshot with a standard Firefox browser, in the standard screen resolution (1280×800), on Read More
  • A step back from the open source
    One month ago, I created my first Android app. While the app was a paid one, the reception has been outstanding. I’ve gotten a fair amount Read More
  • Facebook shuts down EventPress development.
    When you’re a big company, especially one that makes its money on free web services and advertising, it’s very easy to say you love open Read More
  • Why Android is laggy
    Great post from Andrew Munn explaining some key differences between Android and iPhone/iOs, especially when it comes to rendering and smoothness of animations and why Read More
  • Google Plus keeps your data as much as Facebook does
    When you delete an account from Google+, Google promises you to delete all the data associated with your G+ profile. Well, I deleted mine some time Read More