'How to get the process id (PID) of an app launched using `open` command on OSX?

I've launched an application via the open command on the OSX command line like so:

open -a "/Applications/Adobe After Effects CC/Adobe After Effects CC.app"

I want to get the process id of that launched application. Is there any way to do this reliably on OSX? It doesn't seem open returns anything, so I'm not sure I can even pipe its result into something like ps to perform a grep operation. I thought that maybe since the app is launched via the terminal I would know which app is the frontmost, but am doubting the reliability of that solution. Any ideas?



Solution 1:[1]

These days, pgrep -n $APPLICATION_NAME seems like the easiest way to accomplish this. From the man page:

-n    Select only the newest (most recently started) of the matching processes.
-o    Select only the oldest (least recently started) of the matching processes.

Solution 2:[2]

Activity Moniter

You can use Activity Moniter. Located in /System/Applications/Utilities/Activity\ Monitor.app

Open the app, hit the search bar on the top and search for the app you want to get the PID of. Example

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Carter
Solution 2 Kiefer Lin