I am getting the list of running applications in Cocoa with the following code:
for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) {
MNSLog(@"%@",[app localizedName]);
}
However an application I started from a terminal session is not appearing in the list ('Terminal' is well appearing). The application was started from the same user which is executing the cocoa code.
Is my launched application under Terminal ? And in such a case how can I find its name and arguments ?
Running ps in another terminal session show my process properly.
Use an NSTask
to execute the ps
Shell command. You can check the ps
man page to determine which arguments you want to pass it based on the information you want to get back. Use NSPipe
and NSFileHandle
to get the results from the task.
If you want to do some filtering you can pipe the ps
output through grep
before your app picks up the result.
For your first question, I think NSWorkspace
can only see apps that use the window server so you will only see Terminal, not the executables that it is running internally.