1

For a support information gathering tool, I like to be able to look up several apps by name (or rather by their bundle ID) and fetch their versions.

I don't like to use the find command for this as that's not going to find all possible apps, or it'll take forever.

There's lsregister -dump, which knows about all those apps that interest me, but that command seems to offer no option to look up information only about specific apps. I'd have to filter the result with grep, but can't figure out how to filter it so that I can look for an app's bundle ID but also get the version (which appears in a different line).

There's also mdfind, which might be suitable for my purpose.

Let's, for instance, say I want to know about all installed "Word" apps, such as the 2008, 2011 and 365 versions.

With lsregister -dump | grep 'com\.microsoft\.Word', I'd get these lines:

identifier:    com.microsoft.Word (0x800460c2)
activityTypes: NOTIFICATION#:com.microsoft.Word, pv-e851f8544284d1

That's not helpful to inquire the version, is it?

With mdfind "kMDItemCFBundleIdentifier == com.microsoft.Word" I'd get the paths:

/Applications/Microsoft Office 2008/Microsoft Word.app
/Applications/Microsoft Office 2011/Microsoft Word.app

But how would I get the version from that? I thought I'd filter the resulting paths with xargs but that doesn't work with the spaces in the paths.

  • You can read from *.app/Contents/Info.plist file. I'll provide a answer with details. – Vagner Nov 14 '16 at 16:03
  • Parsing the Info.plist is overkill, I think, though. – Thomas Tempelmann Nov 14 '16 at 16:05
  • defaults is your friend ;) – Vagner Nov 14 '16 at 16:21
2

A solution using mdfind and mdls as a one-liner:

mdfind "kMDItemCFBundleIdentifier == com.microsoft.Word" | while IFS= read -r path ; do echo "$path"; mdls -name kMDItemVersion "$path"; done

This would print (if both Office 2008 and 2011 are installed):

/Applications/Microsoft Office 2008/Microsoft Word.app
kMDItemVersion = "12.3.6"
/Applications/Microsoft Office 2011/Microsoft Word.app
kMDItemVersion = "14.6.9"

That's good enough for my needs. I still wonder if there's a way to get the information from lsregister or a similar tool that looks into the Launch Services registry.

1

There is a fast way to look which version is installed for all apps from a particular folder.

Taking an example, /Applications folder:

find /Applications/*/Contents -iname "Info.plist" -maxdepth 1 -exec defaults read {} CFBundleExecutable \; -exec defaults read {} CFBundleVersion \;

This will print app's name and version.

To print app's name:
defaults read nameOf.app/Contents/Info.plist CFBundleExecutable

To print app's version:
defaults read nameOf.app/Contents/Info.plist CFBundleVersion

If you need just for one particular app just change find search.

Anything like this:

find /Applications/*Word/Contents -iname "Info.plist" -maxdepth 1 ...

To use this, you just must know app's folder location.

  • Yes, that works, but that's not at all what I asked, or meant to. A user may place the app anywhere, not just in the Apps folder. It may even be on a different volume. Hence, find is not a good solution. And it's slow, which I already pointed out as well as a no-go. – Thomas Tempelmann Nov 14 '16 at 17:18
  • 1
    @ThomasTempelmann, I know that, but once you find where is the .app with mdfind (or anything else), just run defaults read /full/path/toAn.app/Contents/Info.plist CFBundleVersion and you get the version, as I pointed as a comment in our question. I understood that, the main problem is get app's version, not the location. Right? – Vagner Nov 14 '16 at 18:06
0

The version might be as easy as:

mdls -name kMDItemVersion /Applications/Microsoft\ Word.app/

The find is also easy with spotlight:

mdfind "kMDItemKind == 'Application'" | head

Above I only got the first 10 responses with the | head command. You would need to chose a scripting language or idiom to handle the passing of the results from the find to the examination of the version. Or you could put them in temporary files. You'll need to handle spaces in the file names or just copy / paste things once you see which list of apps you need.

  • Yes, I could use mdls to get the version. But how do I get the path when I don't know it? I want to find any app that matches a specific bundle ID, not a hard-coded path. And I suck at shell scripting, so I am still stuck at figuring out how to pass the list of paths to mdls – Thomas Tempelmann Nov 14 '16 at 15:47
  • @bmike You want more or less which will page the output head takes the first 10 lines by default – Mark Nov 14 '16 at 16:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .