Skip to content
python script to pull down the APOD and, in OS X, GNOME, and fluxbox, set the desktop background.
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

written by Kyle Isom <>

This is a wee little python script to pull down the APOD and, for a few
operating systems / desktop environments, possibly set the desktop 
background. It does handle exceptions, writing useful (usually) error 
messages to stderr. 

- python and the following python modules:
    - argparse
    - OS X: appscript
    - GNOME: gconf

If you are missing any of the python modules, you can try installing the
package python-setuptools and then running:
    sudo easy_install argparse appscript (for OS X, substitute gconf for

The default behaviour of the script is to:
    1. load the APOD page and determine what the APOD is.
    2. grab the APOD url.
    3. open a temporary file and save the image there.
    4. determine the filename to save the image as the base name from the 
       APOD (i.e. images/1011/APOD_cool_pic.jpg -> APOD_cool_pic.jpg) and 
       append the date the image was grabbed, i.e. APOD_cool_pic_20101110.
    5. check to see if a file with that name exists in the given path.
    6. if not, save the file. if the file already exists, exit the script.
    7. if the file was saved and the --set flag was passed, check to see
       what OS the host is running. currently only supports setting the
       wallpaper in OS X. 
    8. fin.

The default directory to save images in is ${HOME}/Pictures/apod/
I have no idea if ${HOME} is set in windows. Please note that since I do
not have any win32 systems, I haven't tested this script under windows.
Caveat emptor.

usage: [-h] [-f] [-o] [-p PATH] [-s] [-t]

wee little python script to grab NASA's APOD

optional arguments:
  -h, --help            show this help message and exit
  -f, --force           force setting background, even if image exists already
  -o, --overwrite       overwrite existing image
  -p PATH, --path PATH  path to store downloaded images in
  -s, --set             flag to cause the script to set the desktop background
                        to the downloaded image.
  -t, --timestamp       flag to cause timestamps to be prepended to progress
                        and error messages.

I designed this to be a cronjob. My crontab entry looks like this:
15  22  *   *   *  python ${APOD_py}/ -s 

To log timestamped progress and error messages to a logfile, use this:
15 22 * * * python -t >> /var/log/apod.log 2>&1 

    - OS X
    - GNOME
    - fluxbox (via fbsetbg or Esetroot, prefers Esetroot)

    - awesomewm

    DO NOT PLAN TO SUPPORT (i.e. do it yourself):
    - win32
    - kde

Something went wrong with that request. Please try again.