10

How can i get a list of running applications in the same order they appear when doing ⌘ + ⇥ from within an applescript?

I.e. if I use TextEdit, then Preview, then iCal, the order is

iCal, Preview, TextEdit

This question which asked if there was an API that could produce this list provided this answer:

$ cd /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework

$ nm LaunchServices | grep __LSCopyApplicationArrayInFrontToBackOrder

But how can I access this list from within an applescript?

Community
  • 1
  • 1
user247298
  • 429
  • 1
  • 7
  • 17

2 Answers2

8

Not sure as how to order them But this lists applications that are not background only

tell application "System Events" to get the name of every process whose background only is false
ikoderuk
  • 144
  • 1
  • 4
8

tell application "System Events" to get name of every process

It looks sorted by launch date to me, but I don't know if that's reliable or not.

As for using the answer from SO: you would have to create a small program (or OSAX) in (Objective)-C to access that routine, make the program scriptable, then call that program/OSAX from your script.

RyanWilcox
  • 13,890
  • 1
  • 36
  • 60
  • 1
    This is definitely not a list of applications sorted by command-tab. It is not even a list of apps; it's a list of low-level processes, like system events. – Michael Matthew Toomim Mar 06 '12 at 03:33