-
-
Save erfanoabdi/70cbc337f9903c59d84461eb30b99c00 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# 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 | |
host='http://bing.com' | |
path='HPImageArchive.aspx' | |
query="format=js&idx=${1:-0}&n=1&mkt=en-US" | |
# $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 | |
saveDir="$HOME/Pictures/BingDesktopImages/" | |
# 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 | |
picName=${defaultPicURL##*/} | |
# 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 | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment