Set your app delegate as delegate of the main window, and implement these method:
- (void)windowDidBecomeKey:(NSNotification *)notification
{
[foobar setEnabled: YES];
}
- (void)windowDidResignKey:(NSNotification *)notification
{
[foobar setEnabled: NO];
}
About first responder
The first responder is a NSControl that is inside the window.For example on a particular window you have two text fields: textField1 and textField2.When you type the input goes just to the first responder (one between all the controls that accept the first responder).So what you need is to know which window is key, you don't need to know who is the first responder in your specific case.
EDIT
There is also another (maybe faster, but depends on personal preferences) way to do it: through interface builder, select the menu item that you want to make enabled only when a certain window is key.Let's suppose that this window is an ivar of the app delegate named window1.Then click on that menu item, go to the bindings inspector, under "enabled" select bind to: app delegate, model key path: self.window.isKeyWindow.
A little image hint: