pub unsafe extern "C-unwind" fn GetCurrentProcess(
p_psn: *mut ProcessSerialNumber,
) -> i16Processes only.Expand description
Return the ProcessSerialNumber of the current application.
Use [ NSRunningApplication currentApplication]
Return the canonical process serial number to the caller.
All applications ( things which can appear in the Dock or which are not documents and are launched by the Finder or Dock ) on Mac OS 10 have a unique process serial number. This number is created when the application launches, and remains until the application quits. Other system services, like AppleEvents, use the ProcessSerialNumber to specify an application.
During launch, every application ‘checks in’ with the Process Manager. Before this checkin, the application can not receive events or draw to the screen. Prior to Mac OS 10.2, this ‘check in’ happened before the applications’s main() function was entered. In Mac OS 10.2 and later, this ‘check in’ does not happen until the first time the application calls a Process Manager function, or until it enters CFRunLoopRun() for the main runloop. This allows tools and other executables which do not need to receive events to link against more of the higher level toolbox frameworks, but may cause a problem if the application expects to be able to retrieve events or use CoreGraphics services before this checkin has occurred.-
An application can force the connection to the Process Manager to be set up by calling any Process Manager routine, but the recommended way to do this is to call GetCurrentProcess() to ask for the current application’s PSN. This will initialize the connection to the Process Manager if it has not already been set up and ‘check in’ the application with the system.
This function is named MacGetCurrentProcess() on non Macintosh platforms and GetCurrentProcess on the Macintosh. However, even Macintosh code can use the GetCurrentProcess() name since there is a macro which maps back to GetCurrentProcess().
Lastly, it is usually not necessary to call GetCurrentProcess() to get the ‘current’ process psn merely to pass it to another Process Manager routine. Instead, just construct a ProcessSerialNumber with 0 in highLongOfPSN and kCurrentProcess in lowLongOfPSN and pass that. For example, to make the current process the frontmost process, use
ProcessSerialNumber psn = { 0, kCurrentProcess };
OSErr err = SetFrontProcess(
&
psn );If you need to pass a ProcessSerialNumber to another application or use it in an AppleEvent, you do need to get the canonical PSN with this routine.
Parameter pPSN: where the current processes process serial number is returned
Returns: An operating system status code.
§Safety
p_psn must be a valid pointer.