TUAW recently posted an item referencing a Daring Fireball post about how to change the OS X
Weather Widget to show the last updated time so that it now works correctly in Snow Leopard. The TUAW article was submitted by an admitted non-JavaScripter, and it contains an important functional bug.
The bug causes the widget to show the current time, rather than the last update time.
// Format the time of the last data refresh
var currentTime = new Date();
var h = currentTime.getHours();
var m = currentTime.getMinutes();
Instead of doing this, I noted that the object.time variable referenced by Gruber is still present, but it doesn't have object.time.hour or object.time.minute specified. Instead, it's always a four-digit timestamp, so I split it and reassemble the digits as strings.
var hhmm = object.time;
hhmm = hhmm.split('');
var hr = '' + hhmm.shift() + hhmm.shift();
var min = '' + hhmm.shift() + hhmm.shift();
After this, it's just a matter of formatting the time (similar to the Gruber code).
- First, launch Terminal.
- If you have an old customized copy of the Weather Widget, either move it out of the way or remove it.
osx:~ $ rm -rf Library/Widgets/Weather.wdgt
- Make a new local copy of the Weather Widget. Your version will be found before the Apple-distributed system version.
osx:~ $ mkdir -p Library/Widgets/Weather.wdgt
osx:~ $ cp -r /Library/Widgets/Weather.wdgt/ Library/Widgets/Weather.wdgt/
- Apply the patches that were described in the Daring Fireball article as well as JavaScript updates to show the last-updated time. Here's the one-step command:
osx:~ $ curl http://www.csh.rit.edu/~mfisher/code/weather-widget/weather-widget.patch | patch -p1 Or if you want to review the patch,
osx:~ $ curl http://www.csh.rit.edu/~mfisher/code/weather-widget/weather-widget.patch > weather-widget.patch
osx:~ $ more weather-widget.patch
osx:~ $ patch -p1 < weather-widget.patch - If you prefer 12-hour time to 24-hour time, edit Library/Widgets/Weather.Wdgt/Weather.js. Around line 268, you should see this line:
if (0) { // change this 0 to 1 for 12 hr time (eg "7:42 am")As noted in the comment, change the 0 to a 1 and you'll be set. - If you already have the widget shown on your dashboard, remove it and re-add it. Otherwise, just add it.