Skip to content

Instantly share code, notes, and snippets.

@rachelss
Forked from bergeycm/set_NatGeo_img_as_desktop.sh
Last active December 17, 2022 10:51
Show Gist options
  • Select an option

  • Save rachelss/f0cfb28b5cf290f5ab32 to your computer and use it in GitHub Desktop.

Select an option

Save rachelss/f0cfb28b5cf290f5ab32 to your computer and use it in GitHub Desktop.
Sets National Geographic's Image of the Day as Desktop background for Mac OSX
#!/bin/bash
cd ~/Pictures/NatGeo
rm NG_img_of_day
rm NG_img_of_day_site
curl http://photography.nationalgeographic.com/photography/photo-of-the-day/ \
-o NG_img_of_day
# Parsing HTML like this is a sin.
# If it's no longer tagged with "canonical," script will break
IMG_HTML=`grep "canonical" NG_img_of_day | sed -e "s/.*href=\"//" -e "s/\".*//"`
curl $IMG_HTML -o NG_img_of_day_site
# Another hacky bit that will fail when Nat Geo changes their image naming conventions
IMG_URL=`grep "wpf/media-live/photos/000/" NG_img_of_day_site | head -n1 | \
sed -e "s/.*\(images\)/\\1/" -e "s/.jpg.*/.jpg/"`
DATE=`date +%Y-%m-%d`
curl http://$IMG_URL -o national-geographic-photo-of-the-day_${DATE}.jpg
# Set desktop background to image
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db \
"update data set value = '~/Pictures/NatGeo/national-geographic-photo-of-the-day_${DATE}.jpg'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment