Noitidart
Noitidart

Reputation: 37238

Get a list of all running applications and get their PIDs?

Is it possible to get a list of all current running applications.

The closest I got was to use [NSRunningApplications runningApplicationsWithBundleIdentifier] but this only returns if it has an exact bundle identifier of what i supply it.

After I get the list i hope to get the pids of each by going [NSRunningApplication processIdentifier] on each element in the array.

And [NSRunningApplication bundleIdentifier]'s

Thanks

Upvotes: 0

Views: 1658

Answers (1)

A O
A O

Reputation: 5698

[[NSWorkspace sharedWorkspace] runningApplications]; should do the trick for you.

Edit: If you want the PIDs, you need to go through every element (NSRunningApplication) in the NSArray returned from runningApplications. Then you can access the processIdentifier property from the element.

For example, this would be grabbing the first running application. [(NSRunningApplication*)[[[[NSWorkspace sharedWorkspace] runningApplications] objectAtIndex:0] processIdentifier].

Upvotes: 3

Related Questions