Getting the name of the foreground app

I need to get the name of the foreground application on a mac. (And perhaps windows…)

Help!

On the Mac you can use the MBS plugins or declares, however I have this gut feeling that you already may not be able to do so, or in the very near future you won’t be able to do so.

[NSWorkspace runningApplications] will return an NSArray listing the applications. You then check [NSRunningApplication active] to see which one is foremost.