Getting the list of running applications ordered by last use

前端 未结 4 622
长情又很酷
长情又很酷 2020-12-03 00:14

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

相关标签:
4条回答
  • Try enumerating the list of windows with the Accessibility or CGWindowList APIs. Apps aren't windows on Mac OS X, as I'm sure you know, but the front-to-back order of applications should be determined by the front-to-back order of their frontmost windows.

    You will, of course, need to ignore processes you've already seen windows from (that is, only consider their frontmost windows).

    0 讨论(0)
  • 2020-12-03 00:42

    You need to register for notifications when the active application changes, as outlined here: http://www.unsanity.org/archives/000045.php

    Once that is done it is easy to maintain an array of active applications sorted by last active time.

    0 讨论(0)
  • 2020-12-03 00:45

    It is impossible to get the list before your application launches. After you start the application though, you can just register for notifications and maintain your own array of applications.

    The only solution is to start a background process at login using launchd that simply listens for applications.

    0 讨论(0)
  • 2020-12-03 00:46

    Maybe something like this:

    cd /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework
    nm LaunchServices | grep __LSCopyApplicationArrayInFrontToBackOrder
    
    0 讨论(0)
提交回复
热议问题