Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Created April 22, 2015 05:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rocktronica/eea944ad0d786904f6b5 to your computer and use it in GitHub Desktop.
Save rocktronica/eea944ad0d786904f6b5 to your computer and use it in GitHub Desktop.
#!/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
}
@rocktronica
Copy link
Author

Work in progress.

More accurately: "Astronomy Picture of the Day" desktop and probably only for some specific flavor of OS X.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment