Skip to content

Instantly share code, notes, and snippets.

@indragiek
Created November 19, 2011 20:04
Show Gist options
  • Save indragiek/1379289 to your computer and use it in GitHub Desktop.
Save indragiek/1379289 to your computer and use it in GitHub Desktop.
Automatically updating NSDockTile with badge count
@interface AppDelegate : NSObject
@property (nonatomic, assign) NSInteger badgeCount;
@end
@implementation AppDelegate
@synthesize badgeCount;
// Override the badgeCount setter to update the dock tile whenever the count is set
- (void)setBadgeCount:(NSInteger)count
{
badgeCount = count;
NSDockTile *tile = [NSApp dockTile];
// Show the badge if the count is larger than 0
if (badgeCount) {
[tile setShowsApplicationBadge:YES];
// Set the label to a string that shows the numerical value
[tile setBadgeLabel:[NSString stringWithFormat:@"%ld", badgeCount]];
} else {
[tile setShowsApplicationBadge:NO];
[tile setBadgeLabel:nil]
}
}
@end
@dsrizvi
Copy link

dsrizvi commented Mar 8, 2016

Can you show me an easy example of how to make a simple dock tile app?

I'd like to add an unread count for my Coherence (a chrome wrapper) Google Inbox app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment