Right now I'm developing a Status Bar Application and I need to know when the app loses focus, every time. So I am currently using applicationDidResignActive:
for that but that's not catching when I open another Status Bar App's menu.
How can I make applicationDidResignActive:
(or any other method) catch every time my app loses focus, even when opening another Status Bar App?
How to make a Status Bar Application catch 'applicationDidResignActive:' with other Status Bar Apps?
Asked
Active
Viewed 570 times
2

Pedro Vieira
- 3,330
- 3
- 41
- 76
-
would it help if you you are listening to NSApplicationNotifications (willHide/Unhide instead of resignActive) ?https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/20000012-BAJDHBID (ps: I haven't done any Mac OS programming, but on iOS, i have found UIApplicationNotificaitions are much more helpful) – Nitin Alabur Dec 31 '12 at 16:31
1 Answers
3
I think what you're actually looking for is when the window looses focus.
You can use the following NSWindowDelegate
method:
windowDidResignMain:
You also have to set canBecomeMainWindow
to YES
- (BOOL)canBecomeMainWindow {
return YES;
}
Make sure to connect it to the delegate and you should be fine.

IluTov
- 6,807
- 6
- 41
- 103
-
I'm sorry, but I've done that and it's not working. I don't get any notification when I open another status bar app's menu – Pedro Vieira Jan 01 '13 at 19:18
-
-
And you have subclassed the window, setting `canBecomeMainWindow` to `YES`? – IluTov Jan 01 '13 at 20:11
-
yes, I have the `canBecomeMainWindow` method in my NSWindow subclass and I'm setting it to `YES`. – Pedro Vieira Jan 01 '13 at 20:14
-
I figured out that my NSWindow must have a title bar for that method to work. But I need it without title bar. Is there any way to work around this? – Pedro Vieira Jan 01 '13 at 23:35
-
-
well, i've tried and it only works if the title bar is displayed. otherwise it won't work – Pedro Vieira Jan 02 '13 at 17:21
-
Are you sure that you are setting the main window correctly? If you click on your status bar, you should set the window to be the main window. It works in the example project above, right? – IluTov Jan 02 '13 at 17:31
-
forget about it, it's working now and to be honest I don't know why it's working now xD but never mind, thanks! – Pedro Vieira Jan 02 '13 at 19:47
-