如何以编程方式确定 OS X 中当前活动的应用程序? [英] How to programmatically determine the currently active App in OS X?

查看:69
本文介绍了如何以编程方式确定 OS X 中当前活动的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在后台工作的简单状态栏应用程序.我想知道当前哪个应用处于活动状态.

I have a simple statusbar applicationn which work in background. I want to know which app currently is active.

有可能吗?

推荐答案

查看NSRunningApplication 类及其活动属性(我已为您链接了文档).您可以查看一系列正在运行的应用程序并找到活动"的应用程序.

Take a look at the NSRunningApplication class and its active property (I've linked the documentation for you). You can look at an array of running applications and find the one that's "active".

哦,要获得正在运行的应用程序数组,您可以通过 [NSWorkspace currentWorkspace] runningApplications].

Oh, and to get that array of running applications, you can do that via [NSWorkspace currentWorkspace] runningApplications].

希望这有帮助!

这篇关于如何以编程方式确定 OS X 中当前活动的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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