Getting the list of running applications ordered by last use

cocoa, list, process

Solution

Maybe something like this:

cd /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework
nm LaunchServices | grep __LSCopyApplicationArrayInFrontToBackOrder

Problem

I'd like to get the list of running applications in the same order they appear when doing ⌘ + ⇥ I.e. if I use TextEdit, then Preview, then iCal, the order is - iCal - Preview - TextEdit Using `[[NSWorkspace sharedWorkspace] launchedApplications]` does not work as applications are sorted by launch date/process id. Enumerating with `GetNextProcess` does not work either as it is also ordered by pid. Registering for notifications and maintaining a list myself is not an option as I must know the list right after the application launches. Well, the first element of the list would be enough actually, but I think it is pretty much the same question. Is there some API available to get this information?

Original source