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

After executing open -a, you can execute ps command. Doing a grep on the output of ps command gives info on process ID.

ps aux | grep -v grep |grep -i <application name> | awk '{print $2;}'

The one given below gives the elapsed time for the process.

ps aux -o etime,command | grep -v grep |grep -i <application name> | awk '{print $2, $12,$13}'

We can compare the elapsed time to know the pid of the recently launched one.

Tags:

Macos

Terminal