views:

184

answers:

3

I'm looking for a way to determine the second frontmost app. Here's what I mean by that.

Let's say I launch three apps in this order: Xcode, Interface Builder, and my application. If I press Command-tab, I should see four applications in the switcher: (from left to right) my application, Interface Builder, Xcode, and Finder.

Let's then say that I switch to Finder. The new order in the app switcher is: Finder, my application, Interface Builder, and Xcode.

If I then switch back to my application, the order is now my application, Finder, Interface Builder, and Xcode.

I'm looking for an API whereby I can call it and get back that at launch time Interface Builder is the second frontmost app, but that when I switch back to it, it is now Finder.

If it makes any different, my app won't actually appear in the app switcher, since it will be an agent application (LSUIElement = YES).

Is there an API that can do this? The only alternative I've found is to have a timer running that continuously monitors what the activeApplication is, according to NSWorkspace. This works well, except during launch. I'd like to know the second frontmost application at launch, if possible.

Any ideas?

A: 

At launch, wouldn't the second frontmost application be the last application run?

Jason
Presumably. How could I get that?
Dave DeLong
A: 

You'll probably be able to assemble the information from:

Process Manager Reference (GetFrontProcess(), GetNextProcess())

Foundation.framework/Headers/NSGraphics.h (NSCountWindows(), NSWindowList())
Quartz Window Services Reference
CoreGraphics.framework/Headers/CGWindow.h
code.google.com CGSPrivate.h
www.cocoadev.com CoreGraphicsPrivate

johne
After some more research with this, it turns out that the Process Manager's order of processes is totally different from the Dock's order of apps. =(
Dave DeLong
+2  A: 

This question is a duplicate of Getting the list of running applications ordered by last use

0xced
agreed. voting to close.
Dave DeLong