Morpheus
Morpheus

Reputation: 3523

NSStatusItem title not updating when highlighted

I made a small app which shows the CPU temperature in the status bar/Menu bar. It is working fine except it stops updating completely when it is highlighted(when i click on it). And works again when i click elsewhere(highlight is removed.). Is there a way to ensure that the app continues to update when the it is clicked on (highlighted mode).

I am using an NSTimer to get the temperature every 5 seconds. Even if i remove the setHighlight method, the app stops updating if i click on the statusbar app.

Upvotes: 0

Views: 331

Answers (2)

Anni S
Anni S

Reputation: 2026

You can use the solution mention in the thread How to add animated icon to OS X status bar?

however instead of using NSTimer, you can use GCD. You can update image or title whatever you want to do.

Upvotes: 0

Rohan
Rohan

Reputation: 768

You should use NSInvocation for this.

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(reload_Live_Data)]];
[invocation setTarget:self];
[invocation setSelector:@selector(reload_Live_Data)];

timer=[NSTimer timerWithTimeInterval:5 invocation: invocation repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

-(void) reload_Live_Data
{
    [_statusItem setTitle:@“xyz”];
    [_statusItem setIcon:image];
}

Upvotes: 1

Related Questions