Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that updates my desktop background every day with the NASA APOD. Since upgrading to 11.10, that script stopped working, presumably because I'm using gconftool-2 to actually update the desktop background. Is there a new way to do this under Unity?

share|improve this question
up vote 51 down vote accepted

Both Unity and Gnome Shell (Gnome 3) use GSettings now instead of GConf. So in Unity and Gnome Shell you can use the command-line tool gsettings for that. Like gconftool, it lets you get or set an individual key.

You can get the current URI of the background image as follows:

gsettings get org.gnome.desktop.background picture-uri

And set the background URI as follows (which will immediately update your desktop background):

gsettings set org.gnome.desktop.background picture-uri file:///home/serrano/Pictures/y.jpg

Notice that you must prepend the URI with "file://" for this to work (unlike with gconftool).

In order to make your script work with both Gnome 2 and Shell/Unity, you can let it do a Gnome version check first:

gnome-session --version

That will return the version of Gnome. If the version number starts with 3, then gsettings can be used. If it returns a version starting with 2, let your script use gconftool instead.

share|improve this answer
I used this command in Ubuntu 12.04 and system is crashed – YumYumYum Sep 5 '13 at 14:26
@YumYumYum: It's highly unusual that the above commands will crash your system, unless there's something else going on in your system. – Serrano Pereira Sep 5 '13 at 17:22
You can add Cinnamon to the list of Desktop Environment using gsettings ;) – MrVaykadji Jan 7 '14 at 18:36
Notice that you must prepend the URI with "file://" for this to work (unlike with gconftool). <-- This is important! I didn't find this mentioned explicitly anywhere else. – Tom Mar 30 '14 at 19:52
This is fine for the current user logged in. I'd like to know how to programatically change wallpaper of another user! I did try sudo --user=<username> gsettings ... but that failed. – kaiwan May 10 '14 at 7:57

This code randomly changes the wallpaper from a given directory.


PIC=$(ls $DIR/* | shuf -n1)
gsettings set org.gnome.desktop.background picture-uri "file://$PIC"

Save this script and edit your with the command "crontab -e" (it launches an editor where you put this line at the end of the file):

*/1     *     *     *     *         /bin/bash /path/to/
share|improve this answer

Also you can use this:

dconf write "/org/gnome/desktop/background/picture-uri" "'file:///home/YOUR_USER/bg.png'"
share|improve this answer

As it has been already mentioned , changing background can be done using gsettings. It still works in 14.04 LTS and 15.10

I've put together a function for .bashrc

Usage is chbackground /full/or/partial/path/to/image.png

function chbackground
FILE="'file://$(readlink -f "$1")'";
echo changing to "$FILE"
gsettings set org.gnome.desktop.background picture-uri "$FILE"

Sidenote: the question asks specifically for desktops such as Unity. With desktops such as openbox or 9wm you have to use a program known as feh (not installed by default), in the syntax feh --bg-scale /path/to/img (or other -- flags specified in the manual). However, starting nautilus in any of the mentioned desktops, causes the background to switch to the one set in gsettings schema mentioned above.

share|improve this answer

Thanks to Serrano's awesome answer, I was able to write this script which I use as part of my new machine setup scripts to set a black background:

#! /bin/bash
wget "$SRC_URI" -O "$FNAME"
gsettings set org.gnome.desktop.background picture-uri "$FNAME"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.