./hadak

The weather in your Geektool arsenal

by on Dec.11, 2008, under Bash Scripts for OS X, Batch Scripts, Linux, Mac OS X, Visitor Favorite

Sitting in the dark, as many of us geekly types often do, I don't look out the window much. I also don't like surprises. Needless to say, I don't like clamoring out of my cove only to find that it's raining. Or snowing. Or 127º. So, I came up with a simple solution: let Geektool keep me up to date with the weather. This script requires you to have lynx installed, so if you don't already have it, head on over to MacPorts or Fink and grab yourself a copy (either sudo fink install lynx or sudo port install lynx, depending on your flavor.) Dump the following script into your favorite editor, and chmod +x it. (I threw mine into /usr/bin).

 
/opt/local/bin/lynx -dump http://www.wunderground.com/cgi-bin/findweather/getForecast?query=48226|grep 'F\ \/'|grep 'Detroit' | head -n 1|sed 's/\[.*\]//'| sed 's/\ \ \ \ \ //' \
/opt/local/bin/lynx -dump http://www.wunderground.com/cgi-bin/findweather/getForecast?query=48226|awk '/Tomorrow is/'| sed 's/\ \ \ //' \
/opt/local/bin/lynx -dump http://www.wunderground.com/cgi-bin/findweather/getForecast?query=48226|awk '/Today is/'| sed 's/\ \ \ //'
 

Wunderground doesn't update more than about every half hour, so there's no sense in spamming the refresh in Geektool. You will also note that it is set to Detroit, MI. If you don't live in Detroit, and I'm assuming you don't, you'll need to do a smidgen of customization for yourself. Firstly, you will need to exchange 48226 for your own zip code. Second, you will need to change "Detroit" to the city that houses your weather reports. (For example, North Pole, AK gets their weather out of Fairbanks. Searching for North Pole wouldn't return any weather results.) Lastly, you may have to change the path to match your installation of lynx. If you don't know where lynx is installed to, try running "locate lynx" - this should return the path for you. My install was at the top of the list.

It's that simple! You no longer have to be surprised when you walk out of your lair into a hail storm in the middle of June. As always, if you have any questions as to "how" or "why", you may direct them to the comments below, or the contact page above.


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...