Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the list of running applications ordered by last use

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

  1. iCal
  2. Preview
  3. 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?

like image 969
0xced Avatar asked Jun 03 '09 14:06

0xced


1 Answers

Maybe something like this:

cd /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework
nm LaunchServices | grep __LSCopyApplicationArrayInFrontToBackOrder
like image 94
nst Avatar answered Sep 21 '22 13:09

nst