Mac OS X Hack: Autoupdate your desktop background
January 16th, 2008 byMy new favorite site on teh intarwebs is the Mt. St. Helens Volcano-cam. So serene! So pretty! So different from the view out my office window, which always seems to include at least one screaming firetruck, particularly during conference calls!
Ahem. Anyway, the volcano-cam picture on the main site is updated every 5 minutes (ish). I wanted it to be my desktop background and update more or less in sync with the online version.
To my surprise, I could find no way to set this up in the OS X control panels. After poking around a bit, I discovered that it’s actually two separate problems:
- Downloading the image every five minutes, and
- Telling OS X to reload its wallpaper every 5 minutes to get the new version.
The first problem requires some Terminal-fu, so let’s start with the second. We’ll set up the wallpaper to change itself every 5 minutes, rotating among a folder of images. Since this folder will actually have just one image, the net effect is reloading the image every 5 minutes.
- Create a new folder wherever you want to store your image. Mine is in /Users/smei/Pictures/volcanocam.
- In the Desktop & Screen Saver control panel, select “Choose Folder…” on the left hand side and find your folder.
- Leave it selected in that list.
- Check “Change picture:” at the bottom and select an interval. If you feel wild and crazy, check “Random order” too!
Halfway there! Now we just need to get the updated image from online to put in that folder. I wrote a shell script to download the image, and then I set up a cron job to run the script every 5 minutes.
Here’s the shell script. Copy this and put in a file called, for instance, volcanocam.sh, in your home directory.
#!/bin/sh
curl -o /Users/smei/Pictures/volcanocam/volcanocamhd.jpg http://www.fs.fed.us/gpnf/volcanocams/msh/hdimages/volcanocamhd.jpg
Replace the path with the path to the folder you set up above. The name of the file doesn’t matter. Since everyone should revel in the Mt. St. Helens glory, I will not recommend that you replace the URL with another you like more.
Now, make sure your script is executable. Go into Terminal, cd to the directory your script is in, and do
chmod u+x scriptname.sh
And then in the same Terminal window,
crontab -e
Copy this line in to your crontab file:
*/5 * * * * cd /Users/smei/; ./volcanocam.sh >/dev/null 2>&1
Replace /Users/smei with your home directory, and volcanocam.sh with the name of your script. Edit the timing as you prefer; for example, to run every 15 minutes use */15 instead of */5.
The bits at the end (starting with “>/dev/null”) turn off crond’s auto-emailing ‘feature.’ If there’s a problem, I’ll notice once it’s 7pm and there’s a full sunlight pic on my desktop!
But if you want to get email when it fails, take out the 2>&1 part. And, if you’re a masochist and want to get email every freaking time it runs, stop at .sh.
(Thanks to Gloria and Amaia for sharing their amazing cron-fu!)


January 16th, 2008 at 4:10 pm
Hey Sarah,
This is the old style way to turn off cron’s email:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * cd /Users/smei/; ./volcanocam.sh >/dev/null 2>&1
The first “>” redirects standard out to a fake device called /dev/null, which just loses whatever you write to it. This can also be written as “1>” for learning purposes.
The second: “2>” is standard error, which you may not want to toss in /dev/null. You may want cron to send you only errors. In that case remove this:
“2>&1″
which tells cron: wherever you’re sending standard out, send standard error there too.
Thanks for this post! It rocks.
Gloria
January 16th, 2008 at 4:20 pm
Hi Sarah
Good post! I don’t have a Mac but i might try it on my Ubuntu ;)
In Linux you can shorten the cron line by writing
*/5 * * * * cd /Users/smei/; ./volcanocam.sh
That runs every 5 minutes. I guess it’s the same for OS X.
January 17th, 2008 at 9:43 am
Gloria and Amaia…thanks for the tips! I am thankfully no longer accumulating 12 new mail messages per hour in my default mailbox which I didn’t even really know I had.
And the */5 thing did work on OS X - it’s a little less obvious what it’s doing, but I have an unnatural hatred for scrollbars under code blocks so it works out. :)
January 22nd, 2008 at 10:34 am
Hi sarah,
thanks for this bit, probably the most “fun” blog post to show up in the dozen or so I follow
I love watching the sun change across St. Helen as the day goes, those icicles yesterday were awesome to watch melt
can’t wait for spring / summer
January 29th, 2008 at 10:02 pm
Since this is Mac OS X specific you might think about using Apple’s replacement to cron (+ other things), launchd. There’s even a nice freeware gui program for controlling it called Lingon http://lingon.sourceforge.net/ .
February 1st, 2008 at 3:02 pm
Check out FlickrFan for an easier way to do this (and a number of other fun things).
flickrfan.org
February 4th, 2008 at 2:02 pm
@andy - haha, the last week has been less than totally enthralling with all the winter storms sweeping down from Alaska. I anxiously await some targeted global warming. :)
@august - I guess this post betrays my Unix origins…when in doubt, use cron! Thanks for the pointers to launchd and Lingon.
@Mayson - your comment sounded kinda like spam but yay - it’s a real site! Now if only the MSH webcam streamed to Flickr…
April 30th, 2008 at 8:42 am
I’ve been doing something similar for a while now. Being a HD image, it scales up nicely on my 2nd monitor at 1600×1200. The main difference between your solution and mine is I don’t use an intermediate script. My cron runs every 5 mins, and the crontab command is simply:
curl –silent -m 120 -o Pictures/graphics/desktops/msh/volcanocamhd.jpg http://www.fs.fed.us/gpnf/volcanocams/msh/hdimages/volcanocamhd.jpg
The path doesn’t need the ‘/Users/yourname/’ bit, because cron runs with your env variables. The ‘–silent’ option tells it to well, be silent. The ‘-m 120′ option is the maximum time the command should run in seconds, so if the MSH webcam is down the script will abort after 2 mins.
I’ve found that occasionally OSX will display a partially downloaded image if the times overlap, so I just set my desktop to update every 5 secs.
One annoyance is that returning from e.g. a full screen game will un-tick the option to ‘change picture every x’, requiring me to manually open the Desktop Prefs panel and reset it.