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!

8
  • 1
    for me the above command is working fine.
    – g_p
    Commented Oct 3, 2014 at 11:06
  • So the command should work but for some reason it doesn't. At least not for me. Disappointing given that this is yet a fresh install and already buggy. Any ideas on how to get the command to work? Commented Oct 3, 2014 at 11:14
  • @user1841330 install dconf-tools, then use the dconf-editor GUI to manually set the wallpaper using that key and see if it works. If it does, then it probably is a bug and you could file a bug report. If it's not, probably something is preventing gsettings from writing that setting.
    – muru
    Commented Oct 3, 2014 at 11:22
  • ALso test if ~/.config/dconf/ is writable and owned by you. If it is not writable gsettings oddly doesn't produce an error.
    – muru
    Commented Oct 3, 2014 at 11:27
  • I already tried that and yes, the wallpaper can be set using the GUI of dconf-editor. Apart from filing a bug report and presumably doing a re-install of Ubuntu, isn't there anything to be done so as to regain functionality of this command? Commented Oct 3, 2014 at 11:28

2 Answers 2

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
0
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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .