Home > python, ubuntu > Set a wallpaper from command line in Gnome 3 (Unity, Gnome Shell)

Set a wallpaper from command line in Gnome 3 (Unity, Gnome Shell)

Problem
Under Gnome you could set the wallpaper from command line with the following commands:

gconftool-2 --type=string --set /desktop/gnome/background/picture_filename /path/to/image.jpg
gconftool-2 --type=string --set /desktop/gnome/background/picture_options stretched    # stretch the image

You try it again on a newer Ubuntu that uses Unity, and nothing happens! What’s going on?

Solution
The new way of setting a wallpaper is this:

gsettings set org.gnome.desktop.background picture-uri file:///path/to/img.jpg

Notice that you must provide a URI, hence the “file://” prefix.

The first snippet works with Gnome 2. The second one is for Gnome 3. To figure out your Gnome version, launch the command “gnome-session --version“.

Python API
I have a general-purpose Python library called “jabbapylib” (installable with pip). Setting the wallpaper is implemented here. You should use directly the gnome.py module.

This tip is from here and here. Thanks.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: