Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

GetProcessForPID is deprecated; what to use instead?

I have been using GetProcessForPID to get the ProcessSerialNumber for the running application, as in


ProcessSerialNumber psn;

int pid = [[NSProcessInfo processInfo] processIdentifier];

OSStatus error = GetProcessForPID(pid, &psn);


I then use this ProcessSerialNumber to create an event tap with CGEventTapCreateForPSN.


As of OS X 10.9, GetProcessForPID is deprecated.

What is the recommended replacement function in Cocoa or in Core Foundation?


Best,

-Michiel.

Posted on Jan 11, 2014 12:22 AM

6 replies

Mar 3, 2014 5:15 AM in response to Community User

Observe the NSWorkspaceDidLaunchApplicationNotification notification.

In the callback, get the process serial number as follows:


NSDictionary* dictionary = [notification userInfo];

NSNumber* psnLow = [dictionary valueForKey: @"NSApplicationProcessSerialNumberLow"];

NSNumber* psnHigh = [dictionary valueForKey: @"NSApplicationProcessSerialNumberHigh"];

ProcessSerialNumber psn;

psn.highLongOfPSN = [psnHigh intValue];

psn.lowLongOfPSN = [psnLow intValue];

GetProcessForPID is deprecated; what to use instead?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.