More Weather Hacking
July 25, 2005
John Gruber posted an article about a month ago showing how to improve Apple’s Weather widget so that it would show you what time the data had been recorded. I implemented this right away. After a few hours, I found that I was doing too much math just to figure out how old the data was. Gruber’s hacked widget only showed the time of the weather reading, unadjusted for time zone differences or daylight savings. All I wanted to know was how fresh the data was. I dove into the code and hacked it to show something like “18 minutes ago” instead. This iteration worked, but returned nonsense results for readings in different time zones than mine. I sent a note to Gruber, and he showed me where to find the GmtDiff in AccuWeather’s XML response.
I’ve made a set of .diffs that you can use to patch a copy of Apple’s original Weather.wdgt. The .diffs are designed to work with Mac OS X 10.4.2, and include Gruber’s changes to the .html and .css, and mine to the .js files. (Did I mention to do this on a copy of Apple’s files?) Download these files, and place them in your Home directory:
In Safari and Firefox, you can option-click each link to download each file.
parser_js.diff
Weather_css.diff
Weather_html.diff
Weather_js.diff
We’re going to do this in the Terminal. You can find the Terminal in /Applications/Utilities. First, copy Apple’s Weather.wdgt into your home directory (note the -r flag, the .wdgt is really a directory):
cp -r /Library/Widgets/Weather.wdgt ~/Library/Widgets/WeatherTime.wdgt
The UNIX patch patch is a UNIX utility invented by Larry Wall, who later created Perl. This utility automates tedious task of changing any type of text file. Find out more at Wikipedia. utility will do the grunt work for us. Type these commands in the Terminal:
patch ~/Library/Widgets/WeatherTime.wdgt/parser.js ~/parser_js.diff
patch ~/Library/Widgets/WeatherTime.wdgt/Weather.css ~/Weather_css.diff
patch ~/Library/Widgets/WeatherTime.wdgt/Weather.html ~/Weather_html.diff
patch ~/Library/Widgets/WeatherTime.wdgt/Weather.js ~/Weather_js.diff
That’s it! If for some reason this breaks in the future, you can just delete the WeatherTime.wdgt package (directory) from ~/Library/Widgets, and you’ll get Apple’s original widget back in your Dashboard. You can also find and delete WeatherTime with 10.4.2’s Widgets widget.
Please send any bug reports or suggestions to beau@hartshorne.ca.