获取按Cmd + Tab顺序/Z顺序运行的macOS应用程序列表 [英] Get list of macOS running applications in Cmd+Tab order / Z-order

查看:41
本文介绍了获取按Cmd + Tab顺序/Z顺序运行的macOS应用程序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在macOS上的Objective-C中,方法 [[[NSWorkspace sharedWorkspace] runningApplications] )可用于获取系统上正在运行的应用程序的列表.

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

但是,根据 Apple的文档,返回数组中应用程序的顺序是不确定的.

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

我想按用户按Cmd + Tab时出现的顺序获得正在运行的应用程序的列表;也就是说,按照每个应用程序是最前面的应用程序的最新程度的"Z顺序".

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.

这怎么办?

推荐答案

我认为您能做的最好的就是键值观察 NSWorkspace.sharedWorkspace frontmostApplication 属性随着时间的流逝,自己维护列表的顺序.当然,这仅适用于自启动您的应用程序以来最重要的应用程序.其他应用将继续处于无序状态.

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.

这篇关于获取按Cmd + Tab顺序/Z顺序运行的macOS应用程序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆