7

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.

6
  • 2
    I don't know for sure, but I suspect that the download is failing (only downloading a partial file) or the background is being displayed before the download is complete - do you have any way of confirming that the download is complete?
    – lofidevops
    Jan 6, 2014 at 13:21
  • Please see the edit in question.
    – nitishch
    Jan 6, 2014 at 16:16
  • 1
    Try rm /home/$USER/.cache/wallpaper/* before executing script. Let me know if it work.
    – totti
    Jan 8, 2014 at 10:18
  • It worked for today, but since I am facing this issue randomly, I cannot guarantee. Can you please explain why the cache is causing a problem?
    – nitishch
    Jan 8, 2014 at 11:09
  • How today ....?
    – totti
    Jan 21, 2014 at 6:25

3 Answers 3

5
+50

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)

6
  • This command: rm /home/$USER/.cache/wallpaper/* doesn't have nothing to do with the new wallpaper; it only removes the wallpaper used before to launch the script. So, it doesn't help with nothing. Jan 9, 2014 at 9:57
  • You are correct. fixing
    – totti
    Jan 9, 2014 at 10:01
  • Adding that command to the end of the script it also doesn't help. Following your test, after re-login, the desktop will remain without any wallpaper. Jan 9, 2014 at 10:08
  • You may need to reboot. It worked for me
    – totti
    Jan 9, 2014 at 10:24
  • 1
    Yes, this is working for me!!
    – nitishch
    Jan 9, 2014 at 10:51
2

The following command is correct and should work in any circumstance:

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

So, I assume that the main reason why this thing is happen is because, as @d3vid noted in his comment: the download is failing (only downloading a partial file) or the background is being displayed before the download is complete.

To solve your problem be sure that you have a better internet connection when you run the script from your question or try to use curl instead of wget as in the script from my answer here.

5
  • 1
    I don't think the problem is with the download, because, the photo is perfectly fine.
    – nitishch
    Jan 6, 2014 at 16:17
  • 1
    @nitish If the photo is perfectly fine, then run again gsettings set org.gnome.desktop.background picture-uri 'file://PathToImage'. I'm sure that this time it will looks good on your desktop. The problem is that when you run that script, gsettings will probably start before wget to finish completely. And for this I suggested you to use curl instead of wget. Or add a line like sleep 5 after wget line which will make the script to wait 5 seconds before to run gsettings. Jan 6, 2014 at 16:38
  • ..or combine wget and gsettings commands with && operator in the script like this: wget [wget_command_parameters] && gsettings [gsettings_command_parameters]
    – precise
    Jan 6, 2014 at 17:19
  • @RaduRădeanu, I tried that before. I put sleep 5 after wget.In fact, the image that I put on this question is produced by the script even with sleep 5
    – nitishch
    Jan 7, 2014 at 9:11
  • @nitish Then your internet connection is even worse; try with more: sleep 20, sleep 30, etc. Jan 9, 2014 at 10:02
0

Maybe in the script, you should first download the new picture in a temporary file like:

wget --no-proxy --output-document=dwallpaper.temp (...)

And only after the wget command is done, do:

cp dwallpaper.temp dwallpaper

This way, gsettings is always pointing to a file 100% downloaded which may fix the issue you observed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.