Skip to content

Instantly share code, notes, and snippets.

@svdamani
Created April 18, 2015 13:51
Show Gist options
  • Save svdamani/505f6aa243d387cb32c1 to your computer and use it in GitHub Desktop.
Save svdamani/505f6aa243d387cb32c1 to your computer and use it in GitHub Desktop.
Bash script to set Bing wallpaper as desktop background
#!/bin/bash
# Get day from command line (default 0)
[ "$#" -ne 1 ] && set -- "0"
# Options
dir=~/Pictures/BingDesktop/ # Working directory
day="&idx=$1" # Set day. 0 is current day, 1 is previous day, ...
num="&n=1" # No. of images to get
mkt="&mkt=en-IN" # Set required market
res="_1920x1080" # Set required resolution
ext=".jpg" # Set extension for the file
# Actual Script
mkdir -p $dir
bing="www.bing.com"
xml_url=$bing"/HPImageArchive.aspx?format=xml"$day$num$mkt
pic_url=$bing$(echo $(wget -qO - $xml_url) | grep -oP "<urlBase>(.*)</urlBase>" | cut -d">" -f2 | cut -d"<" -f1)$res$ext
wget -q --spider "$pic_url" || exit
pic=$(echo ${pic_url##*/} | cut -d_ -f1)$ext
[ -f $dir$pic ] || wget -q -O $dir$pic $pic_url
gsettings set org.gnome.desktop.background picture-uri "file://$dir$pic"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment