Reputation: 1886
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];
-(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
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