This is just a shell script to automate the process of downloading National Geographic photo of the day that works on Mac OSX. The script downloads the photo of the day in the same directory that it resides.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# This Script downloads National Geographic Photo of the day
# Copyright (C) 2012 Saman Barghi - All Rights Reserved
# Permission to copy, modify, and distribute is granted under GPLv3
# https://github.com/samanbarghi/ngphotodownloader
# Last Revised 22 April 2018, Frank Lin

#Change directory to where the script resides.
BASEDIR=$(dirname $0)
cd $BASEDIR
#######################

#get the image url
img=$(curl -s https://www.nationalgeographic.com/photography/photo-of-the-day/ | grep 'property="og:image"' )
imgUrl="$(cut -d"\"" -f4 <<< $img)"

#get the filename using canonical link
link=$(curl -s https://www.nationalgeographic.com/photography/photo-of-the-day/ | grep 'rel="canonical"' )
filename="$(cut -d"\"" -f4 <<< $link)"
filename="$(cut -d"/" -f8 <<< $filename)"

# #check to see if there is any wallpaper to download
if [ -n "$imgUrl" ]
then
  img_file="$filename.jpg"

  if [ -f "$img_file" ]
  then
    echo "File already exists"
  else
    curl "$imgUrl" > $img_file
    echo "Wallpaper downloaded successfully and saved as $img_file"
  fi
else
  echo "No Wallpaper today"
fi

As this script is really hard coded, please address your suggestions to improve using the comments form. Thanks 😉!