2

I've been using elementary os for the last half a year and now I have installed the latest Ubuntu on my system. On elementary os, I was using this command to change the desktop background:

gsettings set org.gnome.desktop.background picture-uri file:///path_to_image

However, this command does not seem to do anything in Ubuntu. I can change the background by choosing a different image in the Appearance menu but I need to change the background from a script and hence the need for a working command.

When running the above command in a terminal no error is produced. If I run the gsetting get command, it returns the background image it always had, as if nothing happened. It totally ignores my set command. The images I tried this command on are the same images in the /usr/share/backgrounds images that are provided by default. Also, I changed the permissions of the entire background folder (and its contents) to be readable and writable to everyone to no avail.

I tried logging out and back in to see if it produces any changes to the background but nothing happens and even if it did, I wouldn't like to re-login every time the background changes...

Doing an online search yielded no results.

Thank you for your time!

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
user1841330
  • 395
  • 2
  • 4
  • 6

2 Answers2

7

gsettings apparently exits successfully if it could not write the setting:

$ chmod a-w .config/dconf/ -R
$ gsettings set org.gnome.desktop.background picture-uri file:///usr/share/backgrounds/Forever_by_Shady_S.jpg
$ echo $?
0

Either that is stunningly bad design, or a bug. Ensure that the ~/.config/dconf folder and everything in it is writable and owned by you:

sudo chown $USER:$USER ~/.config/dconf -R
chmod u+w ~/.config/dconf -R
muru
  • 207,228
1

I had the same issue, the solution for me was as follows:

  1. change anaconda gsettings to gsettings_old as to not interfer with the systems gsettings.
  2. Add the color scheme to the 'picture-uri' part of the command to 'picture-uri-dark'.
$ gsettings set org.gnome.desktop.background picture-uri-dark file:///usr/share/backgrounds/Forever_by_Shady_S.jpg

here is an easy script to detect theme and set bg

# Set wallpaper
echo "Set wallpaper"
current_theme=$(gsettings get org.gnome.desktop.interface gtk-theme)
echo "current_theme: $current_theme"
if [[ "$current_theme" == *"dark"* ]]; then
    theme="-dark"
else
    theme=""
fi

echo "Clearing background."

I know this looks redundant and mispelled, but it works.

DO NOT ALTER

gsettings set org.gnome.desktop.background picture-uri ""; gsettings set org.gnome.desktop.background picture-uri-dark file:///home/user/active_bg.jpe

echo "output_file file://$output_file" gsettings set org.gnome.desktop.background picture-uri$theme file://$output_file gsettings set org.gnome.desktop.background picture-options "centered" echo