Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# this script is not written by me. Just using it and sharing it here.
# export DBUS_SESSION_BUS_ADDRESS environment variable useful when the script is set as a cron job
#PID=$(pgrep gnome-session)
#export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
# $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
# Form the URL for the default pic resolution
defaultPicURL=$(echo $(curl -s "$host/$path?$query" | jq --arg host "$host" -r '$host + .images[0].url'))
# Set picName to the default picName
# Download the Bing pic of the day at default resolution
wget --quiet -O $saveDir$picName $defaultPicURL
# Set Mac OS X wallpaper
osascript -e 'tell application "Finder" to set desktop picture to POSIX file '"\"$saveDir$picName\""
# Remove pictures older than 30 days
find $saveDir -atime 30 -delete
# Exit the script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment