Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.4: Update Weather widget in the background Desktop
Tiger only hintNormally, Tiger's weather widget only updates when the widget screen is active. This is a rather poor implementation that causes a bit of frustration for people who casually just peek at the weather, but appears to have been intentional.

A minor modification to the widget's underlying Javascript (commenting out four lines of code) will enable the widget to update when the widget display is not active (e.g. in the background). Control-click on the Weather widget in /Library/Widgets and choose Show Package Contents. In the new window that opens, open Weather.js in your favorite text editor. There are two areas to change: the onshow and onhide functions. To find this area, search for function onshow (); the two functions are right next to each other.

In the onshow function, comment out these two lines, as shown:
    //if (timer != null)
    //    clearInterval(timer);
Just below that, in the onhide function, comment out these two lines, again as shown:
    //clearInterval(timer);
    //timer = null;
Save the file, quit the editor, open the widget and hit Command-R, and you should have a constantly-updated widget.

[robg adds: I edited this hint relatively extensively (it originally was a diff of the before and after), so any mistakes are mine. That said, I used these instructions to do the edits, so I'm pretty sure they're right. You'll need to have root abilities to edit this file -- so if you're working in the Finder, you'll need to use Get Info to change its permissions first, and remember to change them back when you're done. In the Terminal, just use sudo to edit with root capabilities.Remember to make a backup before you edit, though in this case, the changes are easy enough to undo...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[13,794 views]  

10.4: Update Weather widget in the background | 12 comments | Create New Account
Click here to return to the '10.4: Update Weather widget in the background' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Update Weather widget in the background
Authored by: anamexis on May 16, '05 12:29:55PM
It's important to know that the
onshow()
and
onhide()
functions present in every widget are there so that the widget uses zero CPU when Dashboard is not active. So beware that your widget may start using up your precious CPU cycles at random times.

On the flip side, onshow() might be used as the only event to fetch new information from the internet, without it, the widget may not update at all. I don't want to delve into the Javascript, but just be watchful of this hint.

[ Reply to This | # ]
why?
Authored by: peragrin on May 16, '05 12:47:38PM

I have to ask why. I use the weather widget 3-4 times a day. I press F12 dashboard comes up, in 2 seconds it has updated, and sometimes it's updated before I push command-r to reload my gmail notifier.

Weather doesn't change that fast.

The only time this is useful is on slower connections, but then you just bog down the connection.

---
I thought once I was found but it was only a dream



[ Reply to This | # ]
Resources
Authored by: lullabud on May 16, '05 12:57:41PM

You must either be using newer, better hardware than my original 12" 867 with maxed out at 640mb memory, or you're not using as many apps at once as I am. I just now tested dashboard and it too 15 seconds for my dashboard to show up and update 5 time-sensitive widgets. (Two weather, one clock, one calendar and one IP#) Having weather update in the background alleviates the onshow() demands.



[ Reply to This | # ]
Resources
Authored by: mahakali on May 16, '05 02:22:16PM

Wouldn't it take up CPU time and memory to upate the widget frequently? Which you want to avoid if you're using older machines.



[ Reply to This | # ]
10.4: Update Weather widget in the background
Authored by: Kool on May 16, '05 01:17:57PM

This is not a smart hint.



[ Reply to This | # ]
10.4: Update Weather widget in the background
Authored by: diamondsw on May 16, '05 02:30:13PM

This is not a smart comment.

Some of us fully understand the ramifications of ongoing processor usage, but just want the information to be there as soon as Dashboard comes up.



[ Reply to This | # ]
I would agree.
Authored by: pxlated on May 16, '05 02:54:28PM

One of the first third party weather widgets I saw was on Ars and the thing he changed (due to complaints I recall) was the updating in the background. Too much CPU and too much bandwidth (for dialup).



[ Reply to This | # ]
10.4: Update Weather widget in the background
Authored by: junklight on May 16, '05 04:33:32PM

Mmm - that's a helpful comment.

personally I have plenty of bandwidth and enough processor headroom and I find the lag in update very annoying so in the whole I think that this is a really good hint.



[ Reply to This | # ]
This is a good hint
Authored by: yoel on May 16, '05 02:53:42PM

I find the update lag (which can be a good 10 seconds) to be extremely annoying, and I'm more than happy to spare a few background cycles to get rid of it. Running "top" and watching the CPU load, the impact appears to be negligible anyway.



[ Reply to This | # ]
10.4: Update Weather widget in the background
Authored by: GlowingApple on May 20, '05 02:01:31AM

Awesome hint!

I have been looking for a way to do this for some time now (well, since I got Tiger anyway), but since I don't know java script (and haven't had the plethora of time to learn) I never made any progress.

I have three weather widgets always active, but whenever I would leave my computer idle for some time and then return it would take a good chunk of time to load Dashboard and refresh all the widgets. Just running to my computer to check the temperature before I went outside (so I knew if I should bring a jacket or not) was a pain if I was in a hurry.

With the little processor usage that having these active all the time uses, I would rather save myself the extra time!

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
10.4: Update Weather widget in the background
Authored by: Thor on May 26, '05 05:01:55PM

Hi,

I used the modified version of the weather widget for some time now. As I never restart my Powerbook (only put it to sleep) I experienced that each weather widget is using up more and more of REAL memory (RPRVT in Top).

After 8 days with approximately 4-6 hours working per day, each weather widget is already using up more than 20MB and has a CPU time (TIME in Top) of more than 50 Min.

I have just restored the original version and I will look if the behaviour ist better now.

Bye,
Thor



[ Reply to This | # ]
10.4: Update Weather widget in the background
Authored by: milllion on Jun 04, '05 05:11:49PM

After using this hint (the lag annoyed the hell out of me) I noticed that my weather widgets were eating too much cpu pie. tut tut.

So, digging around in the code I find this (line 29):

var timerInterval = 120000; // updates every two minutes

which is just silly. So if you don't want to be giving ~20% cpu to a widget every two minutes change this to something more reasonable, e.g. for hourly updates change that line to:

var timerInterval = 60 * 60 * 1000; // updates every hour

much better. you could probably even slow it down more. depends on your definition of "current".



[ Reply to This | # ]