How can I change my desktop background from command line?
Ubuntu – How to change the desktop background from command line
command linewallpaper
Related Solutions
If you can live without icons on your desktop, you can disable right click menu entirely through Nautilus' show_desktop option like this:
gconftool-2 -t bool -s /apps/nautilus/preferences/show_desktop false
Edit: Getting rid only of that menu entry would require patching the Nautilus source. The menu definition is in src/file-manager/fm-desktop-icon-view.c
inside desktop_view_entries[]
(or just search for Change Desktop _Background
). Edit2: See below for HowTo.
Other option would be to use different file manager to draw desktop icons. Maybe PCMan File Manager doesn't have this entry in right-click menu?
Minimal guide to editing & rebuilding Nautilus
As I've noted before, the menu entry is hardcoded to Nautilus, so as far as I know, the only way how to remove it AND keep all other functionality is to edit Nautilus' source and recompile it. Be warned that it will take some time and you'll need some space for all the development packages and compilation itself.
The process was tested with Nautilus Elementary 2.32.2.2, however there shouldn't be any differences for stock Nautilus 2.32.
- Get basic development packages:
sudo apt-get install build-essential fakeroot dpkg-dev devscripts
- Get development dependencies for Nautilus
sudo apt-get build-dep nautilus
- Download Nautilus source - note that this command doesn't require sudo; also, it'll place multiple files to current directory so it's usually good idea to create an extra dir for that.
mkdir nautilus cd nautilus apt-get source nautilus
- The source will be downloaded and extracted to
nautilus-VERSION*
folder (VERSION is, of course some version number, most probably 2.32.something). Get into that folder. - Open file
src/file-manager/fm-desktop-icon-view.c
Search for
GtkActionEntry desktop_view_entries[]
- in my case it's on line 721 however it may differ for your version. It should look like this:static const GtkActionEntry desktop_view_entries[] = { /* name, stock id */ { "New Launcher Desktop", NULL, /* label, accelerator */ N_("Create L_auncher..."), NULL, /* tooltip */ N_("Create a new launcher"), G_CALLBACK (action_new_launcher_callback) }, /* name, stock id */ { "Change Background", NULL, /* label, accelerator */ N_("Change Desktop _Background"), NULL, /* tooltip */ N_("Show a window that lets you set your desktop background's pattern or color"), G_CALLBACK (action_change_background_callback) }, /* name, stock id */ { "Empty Trash Conditional", NULL, /* label, accelerator */ N_("Empty Trash"), NULL, /* tooltip */ N_("Delete all items in the Trash"), G_CALLBACK (action_empty_trash_conditional_callback) }, };
Note that the second array contains
Change Background
- remove it, so you get something like that:static const GtkActionEntry desktop_view_entries[] = { /* name, stock id */ { "New Launcher Desktop", NULL, /* label, accelerator */ N_("Create L_auncher..."), NULL, /* tooltip */ N_("Create a new launcher"), G_CALLBACK (action_new_launcher_callback) }, /* Change Background was here */ /* name, stock id */ { "Empty Trash Conditional", NULL, /* label, accelerator */ N_("Empty Trash"), NULL, /* tooltip */ N_("Delete all items in the Trash"), G_CALLBACK (action_empty_trash_conditional_callback) }, };
Save the file.
- Back in Terminal cd to the source root (if you haven't do so already)
cd nautilus-*
And rundch -l local
This will execute the default$EDITOR
(probably Nano) with the changelog file prepared to input your changes. Write something descriptive after the*
, keep everything else intact. Note that-l local
option is to note local build, you can use anything else instead oflocal
, however it's important to add entry to changelog, otherwise your local build would be overridden by repository version. - Compile and build the package
debuild -i -us -uc -b
For explanation of switches see debuild man page Examples section - Go grab some coffee, this might take some time.
- Once the build finishes (hopefully with success), you'll find bunch of .deb packages in the parent directory. Install them all.
cd .. sudo dpkg -i *.deb
- Logout or restart Nautilus for great justice...
nautilus -q
Look ma', no "Change Background"!
To be 100% sure, it's probably good idea to lock nautilus
package in Synaptic.
Edit: Once you've verified that everything is working fine, you can get rid of build-dep packages using this nifty command. You just need to install aptitude
...
References
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
'file:///home/serrano/Pictures/x.jpg'
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.
Related Question
- Ubuntu – How to remove Change Desktop Background from right click
- Ubuntu – How to change desktop background from command line in Unity
- Ubuntu – change the lock screen background to be different from the desktop background
- Ubuntu – The gsettings command line tool doesn’t change the background
- Ubuntu – How to change desktop background on Mate with a command
Best Answer
Edit: In later versions of Ubuntu (this question was written in 2011, after all), things moved to gsettings. See: How to change desktop background from command line in Unity?
It's a
gconf
setting:/desktop/gnome/background/picture_filename
. You can set its value by running the following:Obviously, replace
<path>
with a full path to the background image you want to display.If you want to see what else is available from a nice GUI, run: