atomikpanda
atomikpanda

Reputation: 1886

Set Title Text Color of NSStatus Item

How can I set the text color of a NSStatus Item's title text color?

This is what i'm using to set the statusItem:

NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"set the timeWSeconds to do shell script \"/bin/date '+%a %b %I:%M:%S %p'\""];


    NSAppleEventDescriptor *timeWSeconds = [[script executeAndReturnError:nil]stringValue];
    [statusItem setTitle:timeWSeconds];

Ok I have tried @Vervious's post and this is what I have and nothing has changed.

-(IBAction)timeWSeconds:(id)sender
{
    NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"set the timeWSeconds to do shell script \"/bin/date '+%a %b %d %I:%M:%S %p'\""];


    NSAppleEventDescriptor *timeWSeconds = [[script executeAndReturnError:nil]stringValue];
    [statusItem setTitle:timeWSeconds];

    NSDictionary *attributes = [NSDictionary
                                dictionaryWithObjectsAndKeys:
                                [NSColor redColor], NSForegroundColorAttributeName, nil];
    NSAttributedString *colouredTitle = [[[NSAttributedString alloc]
                                         initWithString:[timeWSeconds stringValue]]
attributes:attributes];
    [statusItem setAttributedTitle:colouredTitle];

}

Upvotes: 2

Views: 769

Answers (1)

Vervious
Vervious

Reputation: 5569

Set the status item's attributed title to an attributed string of your choice. E.g.

NSDictionary *attributes = [NSDictionary
                            dictionaryWithObjectsAndKeys:
                            [NSColor redColor], NSForegroundColorAttributeName, nil];
NSAttributedString *colouredTitle = [[NSAttributedString alloc] 
             initWithString:[timeWSeconds stringValue]]
             attributes:attributes];
[statusItem setAttributedTitle:colouredTitle];

Upvotes: 2

Related Questions