GeekTool is a preference pane for Mac OS X that allows you to display information directly on your desktop. (Take a look at some examples.) Each piece of information, or “geeklet,” can be either an image, the contents of a text file, or–most interestingly–the results of a shell script.
For my desktop, I wanted to display the National Weather Service‘s detailed text forecast. So, I needed a shell script that would grab the web page for my location, extract the bit containing the detailed text forecast, ditch the unneeded HTML tags, and reformat everything to fit down the side of my screen. Here’s what I came up with:
This really shows the power of the UNIX command line. You can do all the above using only three commands. (Technically, ruby is an interpreter for the Ruby programming language, but used like this, it feels just like a command.) And there are countless other ways to do the same thing. In fact, if you have a better way, please let me know.
If you’re an OS X user and want to set this up for yourself, you’ll need to download and install Geektool, create a new shell script geeklet, and paste the above command string into the command field. Of course, if you don’t live in Ann Arbor, you’ll need to replace the URL passed to the curl command with the address of the NWS web page for your location. Just go to www.weather.gov, punch in your zip code, and copy the URL from the address bar of your browser. Also, the number passed to the fold command at the very end specifies where to wrap the text. For me, 50 characters worked, but you could substitute any number. You should get something that looks like this:
This Afternoon:
Mostly sunny, with a high near 33. East wind
between 6 and 9 mph.
Tonight:
Mostly cloudy, with a low around 23. East
southeast wind around 7 mph.
Tuesday:
Partly sunny, with a high near 38. East wind
between 6 and 10 mph.
Tuesday Night:
Rain and snow likely after 1am. Mostly cloudy,
with a low around 29. East wind between 9 and 11
mph. Chance of precipitation is 60%. New snow
accumulation of less than a half inch possible.
Wednesday:
Rain. High near 43. East southeast wind between
13 and 18 mph, with gusts as high as 25 mph.
Chance of precipitation is 90%.
Wednesday Night:
A chance of rain showers before 1am, then a
chance of rain and snow showers. Cloudy, with a
low around 38. Chance of precipitation is 50%.
Thursday:
A chance of snow showers. Mostly cloudy, with a
high near 40. Chance of precipitation is 30%.
Thursday Night:
Mostly cloudy, with a low around 26.
Friday:
Mostly sunny, with a high near 40.
Friday Night:
A slight chance of rain and snow. Mostly cloudy,
with a low around 30.
Saturday:
A chance of rain and snow. Mostly cloudy, with a
high near 41.
Saturday Night:
A chance of snow. Mostly cloudy, with a low
around 26.
Sunday:
Partly sunny, with a high near 39.
If anyone actually uses this, please leave a comment letting me know.
Update: It has since occurred to me that this might have been a bit easier if I had started with the text-only version of the NWS page. But, really, the code wouldn’t be much different.
Update: Modified to work when there is a hazardous weather advisory.
Update: See the comments section for a way to make the forecast headings bolded or underlined.