Ubuntu – gsettings set org.gnome.desktop.background not working

backgroundbashcommand linegsettings

I am trying to download a daily picture and set it as my background image with:

#!/bin/bash
# clear cache
PICS="/home/pvlkmrv/Pictures"

rm -f ${PICS}/wall.jpg
rm -f ${PICS}/photo-of-the-day

# download photo-of-the-day page
wget http://photography.nationalgeographic.com/photography/photo-of-the-day -O ${PICS}/photo-of-the-day

# parse the url out from the file
url=`cat ${PICS}/photo-of-the-day | grep 'images.nationalgeographic.com.*cache.*990x742.jpg' | cut -d '"' -f 2`

# download the photo
wget http:$url -O ${PICS}/wall.jpg

# set the desktop background
URI=file:///${PICS}/wall.jpg
echo ${URI}
gsettings set org.gnome.desktop.background picture-options 'centered'
gsettings set org.gnome.desktop.background picture-uri ${URI}

The image downloads just as expected, but the background is not actually set. Strangely, it works if I modify URI to include more or fewer forward-slashes, but it does so only once. I end up having to modify the script in what should be a meaningless way every time in order to make this section work.

What could be causing this?

Best Answer

try it this way:

#!/bin/bash
# clear cache
PICS="/home/pvlkmrv/Pictures"

rm -f "${PICS}/wall.jpg"
rm -f "${PICS}/photo-of-the-day"

# download photo-of-the-day page
wget "http://photography.nationalgeographic.com/photography/photo-of-the-day" -O "${PICS}/photo-of-the-day"

# parse the url out from the file
url="`cat ${PICS}/photo-of-the-day | grep 'images.nationalgeographic.com.*cache.*990x742.jpg' | cut -d '\"' -f 2`"

# download the photo
wget "http:$url" -O "${PICS}/wall.jpg"

# set the desktop background
# only two slashes here, because the PICS var already has a leading slash
URI="file://${PICS}/wall.jpg"
echo ${URI}
gsettings set org.gnome.desktop.background picture-options 'centered'
gsettings set org.gnome.desktop.background picture-uri "${URI}"
Related Question