Get pid from the running bundle

Hi,

I have a code which executes a call to LSOpenFromURLSpec() to start an external bundle applicfation.


In order to get a pid for that application I need to have an instance of the NSRunningApplication class.


Is there a simple way to get it?


Thank you.

Replies

Do you mean you want the PID of the application process that was launched, after you launch it?


If you can switch to either -[NSWorkspace launchApplicationAtURL:options:configuration:error:] or -[NSWorkspace openURL:options:configuration:error:], they directly return a reference to the NSRunningApplication.

Hi, Ken,

Yes, that is correct.


However launchApplicationAtURL looks deprecated since 10.15:.

https://developer.apple.com/documentation/appkit/nsworkspace/1534810-launchapplicationaturl


And openURL signature indicates that it returns void and its available since 10.15 (presumably as a replacement for the former).

https://developer.apple.com/documentation/appkit/nsworkspace/3172701-openurl?language=objc


So while I can try the former, I need something to use for the next OSX release.


Thank you.