Created
July 9, 2015 19:10
-
-
Save chew-z/623d5fa9dd7ad914587e to your computer and use it in GitHub Desktop.
script downloading Bing wallpapers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
# 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. | |
#IDX=1 | |
for IDX in 0 1 2 | |
do | |
#xmlURL="http://www.bing.com/HPImageArchive.aspx?format=xml&idx="$IDX"&n=1&mkt=ja-JP" | |
xmlURL="http://www.bing.com/HPImageArchive.aspx?format=xml&n=1&idx=" | |
xmlURL+=$IDX | |
xmlURL+="&mkt=en-US" | |
# $bing is needed to form the fully qualified URL for | |
# the Bing pic of the day | |
bing="www.bing.com" | |
# $PICTURE_DIR 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 | |
PICTURE_DIR="$HOME/Pictures/Bing/" | |
# Create PICTURE_DIR if it does not already exist | |
#mkdir -p $PICTURE_DIR | |
# The desired Bing picture resolution to download | |
# Valid options: "_1024x768" "_1280x720" "_1366x768" "_1920x1200" | |
desiredPicRes="_1920x1200" | |
# The file extension for the Bing pic | |
picExt=".jpg" | |
# 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 | |
# Form the URL for the desired pic resolution | |
# using ggrep (gnu grep (homebrew/dupes) not default Mac grep) | |
desiredPicURL=$bing$(echo $(curl -s $xmlURL) | ggrep -oP "<urlBase>(.*)</urlBase>" | cut -d ">" -f 2 | cut -d "<" -f 1)$desiredPicRes$picExt | |
echo $desiredPicURL | |
# Form the URL for the default pic resolution | |
#defaultPicURL=$bing$(echo $(curl -s $xmlURL) | ggrep -oP "<url>(.*)</url>" | cut -d ">" -f 2 | cut -d "<" -f 1) | |
#echo $defaultPicURL | |
# $picName contains the filename of the Bing pic of the day | |
picName=${desiredPicURL##*/} | |
if [ ! -f $PICTURE_DIR/$picName ]; then | |
'/usr/local/bin/terminal-notifier' -title "Bing Wallpaper" -message "Downloading: $picName ..." 1>/dev/null | |
# echo "Downloading: $filename ..." | |
curl -Lso "$PICTURE_DIR/$picName" $desiredPicURL | |
else | |
'/usr/local/bin/terminal-notifier' -title "Bing Wallpaper" -message "Skipping: $picName ..." 1>/dev/null | |
# echo "Skipping: $filename ..." | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment