Skip navigation

OK, NASA’s astronomy photos of the day are cool. I like spacey-type backgrounds. I’d like to have NASA’s photos as my background. But, you see, I’m lazy. I don’t want to have to download and set it every sodding day. I’m on GNOME though, so there’s room for automation with gconftool-2. So I cobbled together some kludge of a script to do it for me.

NASA don’t seem to provide a feed or anything fancy, so it’s a screen-scraper (urgh). Either way, here it is.

Start with some configuration:


Change that to wherever you want the pictures to go to. I decided to make the script keep the files around after they’ve been used, so I can go back and look at them.

Now for the screen-scraping:

wget -O page

Grab the page.

IMG=$(grep -ioP '<img.*' page | sed 's/.*"\(.*\)"/\1/')

Search the page for an IMG tag. The end of the line where the IMG tag is the SRC attribute, so just strip the quotes off that and we’re there. If the format changes, this will be screwed. It’s not flexible, but hey, I can deal.

IMGNAME=$(echo $IMG | sed 's/\(.*\/\)*\(.*\)/\2/')

rm page

Then we mess around with that string to make a local path for the image, and clean up the page.

In order to save some useless work, we can check to see if the image is already there, and quit with a message.

if [ -f "$IMGPATH" ]; then
echo "Picture $IMGNAME already exists, exiting"

Then, if the file isn’t there, we get to actually downloading the thing and setting the relevant GNOME option to point to the file, and we’re done.

wget -O "$IMGPATH" "$URL"

gconftool-2 --type string \
--set /desktop/gnome/background/picture_filename \

Wehay! Easy. And bloody nasty. But there you go.