0

In Objective-C on macOS, the method [[NSWorkspace sharedWorkspace] runningApplications] can be used to get a list of the running applications on the system.

However, per Apple's documentation, the order of applications in the returned array is undefined.

I'd like to get a list of the running applications in the order in which they would appear if the user were to press Cmd+Tab; that is, in the "Z-order" of how recently each application was the frontmost application.

How can this be done?

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170

1 Answers1

2

I think the best you can do is key-value observe NSWorkspace.sharedWorkspace's frontmostApplication property over time and maintain the order of the list yourself. Of course, that only works for the apps which have been made frontmost since your app was launched. Other apps would continue to be unordered.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154