The Robservatory

Robservations on everything…

 

See the launch date and time for any app or process

I was working on something with Peter about Moom and its disk usage (it doesn’t use much), and I was curious as to just how long Moom had been running on my Mac. I last rebooted my Mac a week ago, but I often quit and relaunch our own apps to run test versions.

Finder has this info, but that requires finding the running app in Finder. I wanted a quicker solution. In Activity Monitor (and ps in Terminal), you can see how much CPU time an activity has taken…

…but that doesn’t really help at all with knowing when the app (or process) launched. As long as you’re in Activity Monitor, you can get the information by doing the following:

  1. Click once on the app or process of interest.
  2. Press Command-I or click the small ‘i’ icon in the toolbar.
  3. In the new window that opens, click Sample, then wait.

When the sample is complete, you’ll see its output, and included there is the selected item’s launch date and time:

...
Analysis of sampling Moom (pid 89861) every 1 millisecond
...
Parent Process:  ??? [1]

Date/Time:       2017-02-15 07:41:18.611 -0800
Launch Time:     2017-02-13 19:44:11.957 -0800
...

That’s all fine if you’re in Activity Monitor, but a bit of a pain if you need to launch it, find the app, run a sample, etc.

As you might expect, there’s another way via Terminal: The lsappinfo command, which queries CoreApplicationServices about any app or process on your Mac.

Using lsappinfo, you can see everything it knows about any app by querying on just the app name:

$ lsappinfo info Moom
"Moom" ASN:0x0-0x13a73a6: 
    bundleID="com.manytricks.Moom"
    bundle path="/full/path/to/Moom.app"
    executable path="/full/path/to/Moom.app/binary/Moom"
    pid = 89861 type="UIElement" flavor=3 Version="3181" fileType="APPL" creator="????" Arch=x86_64 
    parentASN="loginwindow" ASN:0x0-0x1394393: 
    launch time =  2017/02/13 19:44:11 ( 1 days, 12 hours, 18 minutes, 30.5074 seconds ago )
    checkin time = 2017/02/13 19:44:12 ( 1 days, 12 hours, 18 minutes, 30.4539 seconds ago )
    launch to checkin time: 0.0534301 seconds

You can see the launch time line there, which you could just read, of course. But lsappinfo has a number of key strings you can feed it; these strings control what information it returns. The key named kLSLaunchTimeKey returns just the piece of data I want, so…

$ lsappinfo info -only kLSLaunchTimeKey Moom
"LSLaunchTime"=2017/02/13 19:44:11

That’s nearly perfect, but you can clean it up a bit more by feeding it to cut to remove the extra text at the beginning:

$ lsappinfo info -only kLSLaunchTimeKey Moom | cut -c 16-36
2017/02/13 19:44:11

So for any running app or process, the above will show you its launch date and time. Still, that’s a lot of typing, and probably not much quicker than using Activity Monitor. But you can speed it up a lot by creating an alias (which has to use a function to pass the app name):

alias alt='function _alt(){ lsappinfo info -only kLSLaunchTimeKey $1 | cut -c 16-36; };_alt'

Put that in your .profile, and you can then do this:

$ alt Moom
2017/02/13 19:44:11

Still not easy enough? If you have Keyboard Maestro, you can make a simple macro to get the launch time for the frontmost app (download the macro):

As seen in the screenshot, I have this macro in the Keyboard Maestro menu item; if I select it, I get a little window showing the launch date/time for the frontmost app:

This was my first exposure to the lsappinfo command; there’s a lot of potentially useful information there, and there’s a good man page for the command that’s worth reading, if you’re into geeky tools.

2 Comments

Add a Comment

Leave a Reply

The Robservatory © 2017 Built from the Frontier theme