I wrote this script because I like the daily Bing wallpapers and didn't think it right that Windows 7 & 8 users should have all the fun. This script does not download from an RSS file of collected Bing wallpapers like others, but rather allows the user, by setting variables in the script to choose the Bing market, image resolution, and save directory they wish to use. After the daily Bing wallpaper is downloaded, the script sets the GNOME3 desktop wallpaper.
Copy the code into your favorite text editor and save it as some-file.sh Be sure to make the file executable with chmod +x so that you can run it from a cron job.
*NOTE* I am very new to bash scripting and would very much appreciate any advice on how to improve and tighten my code!
# $bing is needed to form the fully qualified URL for
# the Bing pic of the day
# $xmlURL is needed to get the xml data from which
# the relative URL for the Bing pic of the day is extracted
# The mkt parameter determines which Bing market you would like to
# obtain your images from.
# Valid values are: en-US, zh-CN, ja-JP, en-AU, en-UK, de-DE, en-NZ, en-CA.
# The idx parameter determines where to start from. 0 is the current day,
# 1 the previous day, etc.
# $saveDir is used to set the location where Bing pics of the day
# are stored. $HOME holds the path of the current user's home directory
# Create saveDir if it does not already exist
mkdir -p $saveDir
# Set picture options
# Valid options are: none,wallpaper,centered,scaled,stretched,zoom,spanned
# The desired Bing picture resolution to download
# Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200"
# The file extension for the Bing pic
# Extract the relative URL of the Bing pic of the day from
# the XML data retrieved from xmlURL, form the fully qualified
# URL for the pic of the day, and store it in $picURL
picURL=$bing$(echo $(curl -s $xmlURL) | grep -oP "<urlBase>(.*)</urlBase>" | cut -d ">" -f 2 | cut -d "<" -f 1)$picRes$picExt
# $picName contains the filename of the Bing pic of the day
# Download the Bing pic of the day
curl -s -o $saveDir$picName $picURL
# Set the GNOME3 wallpaper
DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-uri '"file://'$saveDir$picName'"'
# Set the GNOME3 wallpaper picture options
DISPLAY=:0 GSETTINGS_BACKEND=dconf gsettings set org.gnome.desktop.background picture-options $picOpts
# Exit the script