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?
-
That could be a very long pop-up menu. (Instruments demonstrates this quite well.) You might consider listing the processes in a table view instead. – Peter Hosey Jun 30 '11 at 09:13
-
1i dont mind pop up just that whats the codes – ProSay Jun 30 '11 at 09:41
1 Answers
-[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.
You can filter those out using filteredArrayWithPredicate:
; the objects you want to keep have an activationPolicy
of NSApplicationActivationPolicyRegular
.
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 has a sample project that demos all this, called AppList.

- 63,694
- 13
- 151
- 195