获取进程列表和隐藏特定应用程序 [英] Getting process list and hiding a specific app
问题描述
如何获取进程列表(在弹出按钮中),然后当用户选择应用程序时,我可以隐藏/杀死/最小化/退出应用程序吗?
How do I get a process list (in a popup button), and then when the user selects the application, can I hide/kill/minimize/quit the application?
推荐答案
- [NSWorkspace runningApplications]
会给你一个 NSArray
of NSRunningApplication
表示当前正在运行的进程。我不确定是什么原因导致程序从该列表中排除,但它包括用户已从Finder启动的任何应用程序。它还包括一些你不想混淆的东西(Finder本身和loginwindow过程),以及无面的应用程序。
-[NSWorkspace runningApplications]
will give you an NSArray
of NSRunningApplication
instances representing currently-running processes. I'm not exactly sure what causes a program to be excluded from that list, but it does include any application that the user has launched from the Finder. It also includes a couple of things (the Finder itself, and the loginwindow process) that you don't want to mess with, as well as faceless applications.
您可以使用 filteredArrayWithPredicate:
过滤它们;您要保留的对象具有 NSApplicationActivationPolicyRegular 。
You can filter those out using filteredArrayWithPredicate:
; the objects you want to keep have an activationPolicy
of NSApplicationActivationPolicyRegular
.
数组过滤后,您可以使用 bundleIdentifier
, bundleURL
或 localizedName
找到所需的应用程序。然后发送隐藏
或终止
,你喜欢 NSRunningApplication
实例。
Once the array is filtered, you can search it, using bundleIdentifier
, bundleURL
, or localizedName
to find the app you want. Then send hide
or terminate
as you like to that NSRunningApplication
instance.
Apple有一个示例项目,演示所有这一切,称为 AppList 。
Apple has a sample project that demos all this, called AppList.
这篇关于获取进程列表和隐藏特定应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!