我很难获取应用程序中启动文件的pid。我认为我快到了,但我一直收到一个空:使用NSWorkspace获取已启动应用程序的进程ID
[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
我在做什么错在这里?
这是一个在xcode 4.2中构建的commnand line应用程序。
更改'的NSLog(@ “%@”,PID)''到NSLog的(@ “%i” 的,PID) '为我工作。它给出当前正在运行的应用程序的进程ID,但不是用于打开文件的进程ID。 – Jef
@Jef啊,我需要我刚刚启动的应用程序的进程ID。 – Abs