ADC Home > Reference Library > Technical Q&As > Cocoa > User Experience >

Background-only apps with NSStatusItems become active in 10.1 on NSStatusItem clicks


Q: How do I keep my background-only application from becoming active in Mac OS X version 10.1 when my app's NSStatusItem is clicked?

A: A bug was introduced in Mac OS X version 10.1 that causes a click on an application's NSStatusItem(s) to bring the app to the front, even if the application is a background-only application. This will be fixed in the next major version of Mac OS X, but here is some code that you can use to work around the bug in a relatively safe way:



// NSStatusBarButton is a private class, so put in a cheesy interface.
// Note that this interface is not correct and should only be used to
// allow the following workaround to compile.
@interface NSStatusBarButton:NSButton
@end
// For 10.1 versions of the AppKit, workaround the activation issue;
// for later versions with the bug fix, defer to the kit.
@implementation NSStatusBarButton  (AppKitWorkaround)
 - (BOOL)acceptsFirstResponder {
    return (NSAppKitVersionNumber < 630) ?
        NO : [super acceptsFirstResponder];
}
Listing 1. workaround to prevent NSStatusItem clicks from activating a background-only application




[Oct 30 2001]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.