Recent programs list

Is there any way by program, declare or plugin, to get a list of the recent applications which have been run on Mac OS X ?

The idea is to display a list of the 10 last run apps which most may not be running.

I can monitor regularly running apps through a shell to ps -A and build the list from there, but if that was already done by the system, it would be great. Especially on first run of my app, which by hypothesis will not have the list if I build it from ps.

Any idea will be greatly appreciated.

Thank you in advance.

Have a look at the file com.apple.recentitems.plist in the user’s Library folder.

Thank you. Indeed, the Recent Applications dictionnary is exactly what I meant.

Now as it is in the user library, I probably won’t be allowed to fetch the plist with a sandboxed app :frowning:

I will probably have to settle with opening with a preset “standard” list and update it with ps later.

This is an implementation detail. There is a public API for this, and the process is roughly:

  • invoke LSSharedFileListCreate, passing in kLSSharedFileListRecentApplicationItems
  • invoke LSSharedFileListCopySnapshot with that shared file list
  • invoke CFRelease on the shared file list
  • process the CFArray and do whatever you want with it
  • remember to release the CFArray when done

I believe that you can make a program that would have a Listbox and a timer in mode = 2 would record through an applescript launched the programs and would list in the listbox, I do not know exactly what code Applescript but I’m pretty sure it would work, however, this program would have to be running in background all the time on the machine, so it could be launched at startup items …

[quote=105517:@Joe Ranieri]This is an implementation detail. There is a public API for this, and the process is roughly:

  • invoke LSSharedFileListCreate, passing in kLSSharedFileListRecentApplicationItems
  • invoke LSSharedFileListCopySnapshot with that shared file list
  • invoke CFRelease on the shared file list
  • process the CFArray and do whatever you want with it
  • remember to release the CFArray when done[/quote]

Thanks you Joe. Now I will need some time to create the proper declares :wink:

Exactly what I had in mind, although instead of AppleScript I would use simply a shell to see the running processes, as I described above. Thank you Paulo.