Thursday, September 04, 2008

Andy's Linux Hacks for NOOBs - Phun with screensavers edition

I'm more-or-less a novice user when it comes to linux. I'm pretty proud of having put together the little hack I'm about to describe, but I realize it is kid stuff for those of you who administer commercial grade servers and write kernel patches and stuff. Still, I thought I would share what I did for the benefits of my fellow NOOBs who might find the information useful. Sharing is what FOSS is all about, right?

I've always been fascinated by the variety of real-time and near-real-time information you can access with a networked PC. I remember the first time I found a Full-Disk GOES image on the web. I was amazed, there was the "big blue marble" of the earth, just like in the famous images from the Apollo Missions (except in black-and-white and higher resolution) and I was seeing it as it appeared just a few hours ago! Since then, I've discovered a variety of live or almost-live feeds of interesting images, like the Kennedy Space Center launch pad, or weather radar images, images from traffic cameras on local highways, or from the SOHO satellite monitoring the sun.

Yesterday it struck me that I had all the tools I needed to set up my Linux desktop box (running Ubuntu 8.04) to automatically download images from these feeds and display them as my screensaver. Here's how I did it.

Ubuntu ships stock with a screensaver called glslideshow that displays a slideshow of image files on the screen. I decided to use this to display my images. First I had to modify the settings for the glslideshow screensaver to pull images from a directory other than its default and to forgo panning and zooming the images it displayed. Sadly, Gnome doesn't give you an easy way to do this from the GUI just yet, so I had to go in and edit a couple of config files. First I had to modify the glslideshow config file to get it to display the images the way I wanted to. This file is located at:

The line of this file beginning with:

gives the options that the glslideshow screensaver program will be executed with. I set mine to:
Exec=glslideshow -root -duration 5 fade 1 -zoom 100
Which basically tells the program to show images for 5 seconds at a time with a 1 second crossfade between them, and to display the images at 100% screensize, which prevents any panning or zooming effects. You can read the man page for glslideshow to learn more about the options if you want.

For some reason, to set the location the screensaver will use as the source for its images, you have to edit a different file. This file is called .xscreensaver and is located in your home directory. You may or may not have one. If you have one edit it. If you don't have one, create one. In any event add this line to .xscreensaver:
imageDirectory: [Path to Files]
Substitute the location you want to use to store your files for [Path to Files] I used a subdirectory in my home directory so I used
imageDirectory: /home/MyUserName/Pictures_For_Screensaver

Once you get that set up, throw a couple images into the directory you are going to use and go to the "screensaver" entry under the "preferences" menu and enable the glslideshow screensaver to give it a test run. It should randomly display your test images on the screen.

Next, I set up my machine to download images from my sources at set intervals. To do this I used the program crontab, which tells the computer to execute a specified command at a specified time, to automatically run the program wget, which fetches a file from the internet.

You set up crontab by writing a text file with entries that tell the computer when you want it to execute a given command. This can be a little tricky to understand at first. I'm not going to go into detail about how to use crontab. It is a very powerful little program. If you want detailed instructions on its general use, go here. For our purposes, all we need to know is how to set it up to issue our wget commands at regular intervals. You do this by creating a text file and adding lines in this format
*/[Number of Minutes Between Downoads] * * * * wget -O [Path_to_File/Filename] [URL of File to Download]

Ok, what does all that mean? It means that to tell crontab to have wget grab the file at and save it to /home/User_Name/Pictures_for_Screensaver every 30 minutes you add a line reading
*/30 * * * * wget -O /home/User_Name/Pictures_for_Screensaver/gevs.jpg

What's the deal with all those "*" symbols? Its complicated. Seriously, read this or take my word for it, you need 'em.

Add a line to the file for each of your image sources. Have the computer grab more frequently updated images more often, and less frequently updated images less often. I ended up grabbing images from the following sources:

Which gives me an interesting mix. Some local webcams, some silly stuff, a couple of satellites, weather radar...

Once you have your text file done, save it as a plain text file under any filename you like. I saved mine as "cronfile." Then issue the following command from the command line:
crontab [filename]
Replace [filename] with the name of the text file you created.

And voila! Your own auto-updating webcam screensaver! I'm watching mine right now. It is showing me traffic on I475 in toledo and the slow march of the "crawler" vehicle bringing the space shuttle to the launch pad at Kennedy, as well as the most recent GOES and SOHO images, local weather radar, and the current Aurora activity forcast from the space weather center.

Useful? Time will tell. A nerdy thrill from having a "magic window" out on various parts of the Earth and Outer Space? Hells yes.

1 comment:

cscannella said...

Inspired by your idea, here's the setup for my Mac. This works for OSX 10.5...not sure about previous versions.

The setup is basically the same, except you use the "curl" program to get the files. So, for example, in my text file, I have:

*/30 * * * * curl > ~/Pictures/screen_saver_live/new-york-live.jpg

You can see the difference in syntax; you need the ">" in there to direct the file from the web into a file on your hard drive. "Pictures" is in my home directory (which is specified by "~"), and "screen_saver_live" is where I store my files.

The next step is to configure the Mac screen saver to point to your files -- that's easy. You just go into System Prefs -> Screen Saver. You "Choose folder..." and point to wherever you're downloading the files with curl. Under "Options," you probably want to turn off the "random" setting, as it tends to repeat the images before going through the entire set.

I really like this idea! Off to find more web cams!