APOD script

10.5.2013

A script to automatically set your desktop backgrounds to the latest Astronomy Picture of the Day (APOD) using Python. I have posted it as a Github gist.

Description

A simple python3 script to automatically download the latest Astronomy Picture of the Day (APOD) as an image and set it as the desktop background for all spaces in OS X. Because OS X is a bit unfriendly in how it lets you change the background, python launches an applescript that steps through each space individually. Note that this assumes you have the key bindings ctrl+# mapped to change to a specific space, which can be done in System Preferences.

Note that the delays are required to make sure that the background gets set before the system jumps to the next space, since you can only set a background for the active space. Also, you have to set the number of spaces present manually.

This has been tested on 10.8 only.

I posted the original version a few months ago, and today went back to update it adding some mirror functionality. Unfortunately this is necessary because the government shutdown has closed the NASA website.

Usage

You have to invoke the script at the command line using python3, in terminal ./apod.py or python3 apod.py.

There are two options that can be passed to the script:

Mirror locale

Flag is either --locale or -l and allows passing in a locale for mirror selection. As an example:

   ./apod.py --locale US
   ./apod.py -l UK

The first obviously sets the locale to US and the second sets it to UK. In the posted script, these are the only two locations set up with mirrors, but it is straightforward to add more if you are interested. A list is available from the APOD folks here.

Number of spaces

Define the number of Spaces you are using. This needs to be specified manually because of limitations with how OS X handles this stuff. Perhaps Mavericks will let us do this automatically. Anyways:

    ./apod.py --spaces 5
    ./apod.py -s 3

Downloading

Once again, you can view and download the script from Github. There is also a locally hosted copy here.