Question

I would like to implement an NSStatusItem where the title changes over time. My ultimate goal is to display a countdown timer in the menu bar beside the image which I have set. Maybe I am going about this the wrong way. But I already have a string of characters which are constantly changing over time which represents the timer. I'm trying to figure out how I can place that string beside the image I have set for a menulet I created.

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:"29:30"];

I have tried multiple calls of the setTitle method but they don't seem to work. Only the initial call of setTitle works prior to the object initialization. After that nothing happens. I guess I could release the NSStatusItem Object and recreate it every time I want the timer changed, but that seems very inefficient. I'm not even sure if it would work.

Also I have contemplated using the setToolTip method to display the timer countdown. But that seems to be the same as the setTitle method. Once it is set, you can't change it till you release the NSStatusItem object and create a new one.

Any suggestions would be appreciated.

Thank you

Dave

Was it helpful?

Solution

I answered my own question. -setTitle can be called multiple times in order to change the title dynamically for the countdown timer, a custom view is not required. My problem ran into my timer not functioning correctly and the length of my menulet not being sufficient to display the text of the timer. I can now call setTitle to refresh the countdown and create dynamic tooltips every second. I originally thought it wasn't possible through the standard methods setTitle. I was wrong.

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:"29:30"];

Dave

OTHER TIPS

Why not use it's -setView:? You can create your own custom view and update it however you like.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top