Skip to content

Instantly share code, notes, and snippets.

@kybernetyk
Created June 22, 2011 15:49
Show Gist options
  • Save kybernetyk/1040400 to your computer and use it in GitHub Desktop.
Save kybernetyk/1040400 to your computer and use it in GitHub Desktop.
Keep Status Item Left
if (!statusItem) {
if ([defs boolForKey: @"keepAlwaysLeft"] &&
[statusBar respondsToSelector:@selector(_statusItemWithLength:withPriority:)]) {
NSLog(@"will keep always left!");
statusItem = [statusBar _statusItemWithLength:0 withPriority:INT_MIN ];
[statusItem setLength:0];
} else {
statusItem = [statusBar statusItemWithLength: NSVariableStatusItemLength];
}
[statusItem setEnabled: YES];
[statusItem setHighlightMode: YES];
[statusItem setMenu: statusBarMenu];
if ([defs boolForKey: @"keepAlwaysLeft"] &&
[statusBar respondsToSelector:@selector(_statusItemWithLength:withPriority:)]) {
NSLog(@"still keeping left!");
[ statusItem setLength:NSVariableStatusItemLength ];
}
[statusItem retain];
}
/*
notes:
1) setting the status item's length to 0 first, then changing its properties and then setting the lentght
to a propper length is neccessary. otherwise it won't work. (there will be ugly errors)
2) this is using an undocumented behavior. it might not work in future versions of os x. (though it still
works for 10.7)
3) if the user decides to deactivate the keep always left behavior I destroy the current status item
and create a new. there's no other way to disable this behavior - at least no way I know of.
*/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment