1

There's a nice lsappinfo tool that lets you do things like monitor for app switching. I'd like to write a program that runs lsappinfo listen and takes actions when the foreground app changes (specifically, change LED colors on my new keyboard).

Does anyone know what the serialization format that lsappinfo uses is? It looks like this:

$ lsappinfo listen +becameFrontmost forever
Notification: kLSNotifyBecameFrontmost time=10/18/2017 06:58:18.843 dataRef={ "ApplicationType"="Foreground", "CFBundleIdentifier"="com.google.Chrome", "LSASN"=ASN:0x0-0x10010:, "LSFrontApplicationSeed"=3367, "LSMenuBarOwnerApplicationSeed"=3270, "LSMenuBarOwnerASN"=ASN:0x0-0x10010:, "LSOtherASN"=ASN:0x0-0x2f52f5: } affectedASN="Google Chrome" ASN:0x0-0x10010:  context=0x0 sessionID=186a6 notificationID=0x7fb529d00a90
Notification: kLSNotifyBecameFrontmost time=+0.835684s  dataRef={ "ApplicationType"="Foreground", "CFBundleIdentifier"="org.gnu.Emacs", "LSASN"=ASN:0x0-0x2f52f5:, "LSFrontApplicationSeed"=3368, "LSMenuBarOwnerApplicationSeed"=3271, "LSMenuBarOwnerASN"=ASN:0x0-0x2f52f5:, "LSOtherASN"=ASN:0x0-0x10010: } affectedASN="Emacs" ASN:0x0-0x2f52f5:  context=0x0 sessionID=186a6 notificationID=0x7fb529d00a90

I mean, I can parse this with a regex looking for just the field I want, but it would be nicer to be able to just pass it to some library rather than use a hacky regex that might fail if the data looks weird. Is this some sort of standard macOS internals serialization format that I haven't heard of, or is it something they made up just for this tool?

  • Close voters: This is *not* a software development question. This question is asking about the output format of a command line utility. The OP only references software development for why he wants this info. – Allan Oct 18 '17 at 13:35
  • It looks like quasi-JSON-esque but more than likely, you will have to search for the data via some REGEX statement. This is a really cool tool that I wasn't aware of and now I am looking at it for use with ControllerMate. I have no idea how just yet...but it got me thinking.... – Allan Oct 18 '17 at 13:36
  • Yeah, I was hoping the answer was something like "Oh this is the standard macOS library X serialization format, it's not documented because this is immediately obvious to any Cocoa developer" – David Glasser Oct 18 '17 at 21:50

1 Answers1

1

You don't need to - there's an open source clone of it at http://newosxbook.com/tools/lsdtrip.html which can get you the underlying API calls that Apple uses.