I am having difficulty getting the pid of a launched file in an application. I think I’m nearly there but I keep getting a null:
[sharedWorkspace openFile:@"/Users/abs/Documents/my.txt" withApplication:@"TextEdit"];
NSDictionary * currentAppInfo = [sharedWorkspace activeApplication];
int pid = [[currentAppInfo objectForKey: @"NSApplicationProcessIdentifier"] intValue];
NSLog(@"%@", pid); // (null), using @i, @u, @d I get 0
What am I doing wrong here?
This is for a commnand line application being built in xcode 4.2.
If you’re doing your app as a command line application, you are likely not even using AppKit. Is the AppKit.framework linked in your project?
Does the
[NSWorkspace openFile: withApplication:]call even work?Check out this CocoaBuilder thread. One quote that stands out to me is:
To get the process id (pid) of the TextEdit you launched, I believe you’re going to have to try something else.
Of course you realize that
[NSWorkspace activeApplication]has been deprecated as of 10.7, yes?