Ubuntu – Problem with setting wallpaper using gsettings

gnomegsettingswallpaper

I used gsettings set org.gnome.desktop.background picture-uri 'file://PathToImage' to set an image as a wallpaper as suggested in this answer. This does not do the job properly. For today's bing image, script here changes my background like this

Image of my desktop

This happens at random and sometimes it sets the wallpaper properly. Using GUI, setting the image as wallpaper by right-clicking on it works properly every time. Any possible causes of this problem?

Edit1: The download is perfectly fine. As I have mentioned, I can set the photo as wallpaper by right clicking the photo and chosing 'set as wallpaper' from the menu.

Best Answer

You mentioned

The download is perfectly fine. As I have mentioned, I can set the photo as wallpaper by right clicking the photo and chosing 'set as wallpaper' from the menu.

As you can manually set the wallpaper the problem may be on the cache, which is generated before the downloader completely write the data on the file. So regenerating the cache in this kind of case is necessary.

So delete wallpaper cache rm /home/$USER/.cache/wallpaper/* . Add this code to end of the script after some sleep.

Let's do a test

  1. Find and open the image cache of current wallpaper from /home/$USER/.cache/wallpaper/
  2. Edit the image ( such as rotate clockwise. You can do it with the default imageg viwer (GNOME image viewer) using Ctrl+R (Or from edit -> rotate))
  3. Logout and login ubuntu (or restart)

That's it now you can see the changes on the desktop wallpaper (If you rotated the image, then the wallpaper will also get rotated)