Both Brian and Daniel provided great clues that helped me find the right answer, but the material they suggested was just a little off. This is how I decided to solve the problem.
Brian was right about the code to get the Apple Event descriptor for the process identifier instead of the name for the serial number:
The problem is that if you take -int32Value from this handle, the value 0 is returned (i.e. there is no process identifier). I have no idea why this happens: in theory, both pid_t and SInt32 are integers.
Instead, you need to get the byte values (which are kept a bit endian) and pass them to the process id:
pid_t pid = *(pid_t *)[[pidDescriptor data] bytes];
From this point of view, it is easy to obtain information about the current process:
NSRunningApplication *runningApplication = [NSRunningApplication runningApplicationWithProcessIdentifier:pid]; NSString *bundleIdentifer = [runningApplication bundleIdentifier];
Additionally, Daniel's suggestion for using keySenderPIDAttr will not work in many cases. In our new isolated world, the value stored there will probably be the process identifier for /usr/libexec/lsboxd , also known as the daemon for the Launch Services software environment, and not the process identifier of the application that triggered the event.
Thanks again to Brian and Daniel for the help that led to this decision!
source share