Mike Fisher (mfisher) wrote,
Mike Fisher

OSX Weather Widget Patch

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).

  1. First, launch Terminal.
  2. 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

  3. 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/ 

  4. 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
  5. 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.
  6. If you already have the widget shown on your dashboard, remove it and re-add it. Otherwise, just add it.

Tags: geeky apple widget javascript

  • Request Tracker Note

    At my job, we use Request Tracker for managing our help desks. We basically love it -- but we keep adding new queues for different requirements,…

  • FreeBSD port connectivity workaround

    FreeBSD ports use without DNS/direct connectivity. 1) Set up an SSH SOCKS5 tunnnel. $ ssh -fND localhost:1080 routed_host 2) Override the…

  • Where's the Love, Frontier?

    "If Google built its own network, we estimate it would cost $5,000 per household," said Ann Burr, chairman and general manager of Frontier…

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment