Skip to content

Instantly share code, notes, and snippets.

@rk295
Forked from bergeycm/set_NatGeo_img_as_desktop.sh
Last active June 19, 2018 10:23
Show Gist options
  • Save rk295/0ea95dec7d64eb8f0ed98fae3dadbdfc to your computer and use it in GitHub Desktop.
Save rk295/0ea95dec7d64eb8f0ed98fae3dadbdfc to your computer and use it in GitHub Desktop.
Sets National Geographic's Image of the Day as Desktop background for Mac OSX
#!/usr/bin/env bash
cd ~/Pictures/NatGeo || exit 1
today="$(date +%Y-%m-%d)"
hostname="https://yourshot.nationalgeographic.com"
originalUrl="$(curl -s https://www.nationalgeographic.com/photography/photo-of-the-day/_jcr_content/.gallery.json | jq -r '.items[0].originalUrl')"
fullPhotoUrl="${hostname}${originalUrl}"
curl -s "$fullPhotoUrl" -o "national-geographic-photo-of-the-day_${today}.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_${today}.jpg'"
killall Dock
@rk295
Copy link
Author

rk295 commented Jun 19, 2018

Updated to parse the JSON rather than grep the html source, that method was broken and this is far easier to manage. Also latest MacOS seems to require a killall Dock to actually reload the displayed picture.

And passes shellcheck!

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