问题
I have a simple statusbar applicationn which work in background. I want to know which app currently is active.
It is possible?
回答1:
Take a look at the NSRunningApplication class and its active property (I've linked the documentation for you). You can look at an array of running applications and find the one that's "active".
Oh, and to get that array of running applications, you can do that via [NSWorkspace currentWorkspace] runningApplications].
Hope this helps!
来源:https://stackoverflow.com/questions/10143540/how-to-programmatically-determine-the-currently-active-app-in-os-x