Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
i've noticed in some menu bar apps like Google's GMail Notifier, the time since last email check will display when changed while the menu is visible. how can i emulate this behavior in my own NSMenu with a timer that changes?

Code:
[MainMenu_Item3 setNeedsDisplay:YES];

doesn't work...
 
I tried to do this a while ago but didn't have much luck, and didn't look into it any further. I have a feeling it's new with Leopard since the AirPort menu does this too. You could try posting the question on cocoadev.com/forums
 
FWIW, for those who come across this in the future:

The main way I found to do this is to use an NSTimer and add it to the run loop with the mode set to NSEventTrackingRunLoopMode. When that timer fires you can update the menu like usual. However, I ran into problems with code that was using the main run loop (e.g. NSURLConnection). It never ran when the menu was active, so instead I created a thread with its own run loop and ran the NSURLConnection there so it would use the thread's run loop. Making sure to rebuild the menu items on the main thread, everything works nicely.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.