Created
April 22, 2015 05:18
-
-
Save rocktronica/eea944ad0d786904f6b5 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 | |
{ | |
date_slug=$(date "+%y%m%d") | |
image_filename="$PWD/images/$date_slug.jpg" | |
cache_page_filename="$PWD/cache/ap$date_slug.html" | |
function download_page() { | |
if [ ! -f $cache_page_filename ]; then | |
curl -# -L http://apod.nasa.gov/apod/ap$date_slug.html \ | |
> $cache_page_filename | |
fi | |
} | |
function get_url() { | |
cat $cache_page_filename | | |
grep -oE "href=[^>]*" | \ | |
grep -oE "[^'\"]*.jpg" | |
} | |
function download_image() { | |
if [ ! -f $image_filename ]; then | |
image_url=$(get_url) | |
echo "$image_url\n" | |
curl -# $image_url > $image_filename | |
fi | |
} | |
function set_desktop() { | |
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db \ | |
"update data set value = '$image_filename'" \ | |
&& killall Dock | |
} | |
download_page | |
download_image | |
set_desktop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Work in progress.
More accurately: "Astronomy Picture of the Day" desktop and probably only for some specific flavor of OS X.