Mac OS X - How to monitor a window change event?

2019-04-08 23:52发布

I'm developing a Cocoa application that shows a list of opened windows and highlights the current focused one. My problem is that I can't find a system notification to inform my app that the main (aka "focused" or "foreground") window has changed. I tried with:

    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(wsNotificationHook:) name:NSWorkspaceDidActivateApplicationNotification object:nil];

but it monitors APPLICATION change: it isn't get fired when a change of window is executed INSIDE the same application (for example, if I pass between two Firefox windows using exposè). Is there a system-wide event that I can monitor to track a change of the main window?

Thank you in advance!

1条回答
成全新的幸福
2楼-- · 2019-04-09 00:21

The closest you'll get will probably be the accessibility APIs. See here and here for similar questions with (partial) solutions.

查看更多
登录 后发表回答