Find Application version through terminal / Deploying Office 2016 updates

bbot
Contributor

Hi all,

I'm looking for a way to find Microsoft Office 2016 application version numbers through terminal. I will be using this in a script to push updates.

I'm thinking of having 4 scripts (one for each Office product - excel, word, ppt, outlook), and 4 Policies that have triggers to install each program. Ideally, the script will look for Application versions, if the version found is outdated, it'll trigger the JSS Policy to install the office pkg.

Currently, we use smart groups that search for outdated version numbers and sort by departments, and it's a pain to change 50+ smart groups (due to the large amount of departments we have) when a new version comes out. We want to retain the option of doing by deploying by department.

2 ACCEPTED SOLUTIONS

mm2270
Legendary Contributor III

Using defaults:

defaults read /Applications/Microsoft Word.app/Contents/Info CFBundleShortVersionString

Using mdls (Spotlight's command line interface - for info):

mdls /Applications/Microsoft Word.app -name kMDItemVersion | awk -F'"' '{print $2}'

Either one should report back the version, assuming the app is in the path you specify, otherwise you'll get an error. So just be sure to do a check for the application existing before trying to get the version.
You could also locate the application path using mdfind (Spotlight's command line search interface)

mdfind -onlyin /Applications -name "Microsoft Word"

View solution in original post

Aziz
Valued Contributor
mdls -name kMDItemVersion /Applications/Microsoft Word.app

This would give the version number, would this work?

Mike beat me to it.

View solution in original post

10 REPLIES 10

mm2270
Legendary Contributor III

Using defaults:

defaults read /Applications/Microsoft Word.app/Contents/Info CFBundleShortVersionString

Using mdls (Spotlight's command line interface - for info):

mdls /Applications/Microsoft Word.app -name kMDItemVersion | awk -F'"' '{print $2}'

Either one should report back the version, assuming the app is in the path you specify, otherwise you'll get an error. So just be sure to do a check for the application existing before trying to get the version.
You could also locate the application path using mdfind (Spotlight's command line search interface)

mdfind -onlyin /Applications -name "Microsoft Word"

Aziz
Valued Contributor
mdls -name kMDItemVersion /Applications/Microsoft Word.app

This would give the version number, would this work?

Mike beat me to it.

bbot
Contributor

This is perfect! Thanks for the quick response guys!

calumhunter
Valued Contributor

Isn't casper supposed to help you not need to deploy scripts to do this kinda stuff?

gabester
Contributor III

A note for myself more than anything - if you need to identify the long version string, say, for a smart group or something, you can use this defaults command to retrieve it:

defaults read /Applications/Microsoft Word.app/Contents/Info CFBundleVersion

While this is obviously not specific to Office 2016, the context in which I arrived here was needing to identify Microsoft Office 2016 installed version for a smart group to be upgraded.

donmontalvo
Esteemed Contributor III

Vendors can make mistakes, or conscious decisions, that change how/where their version information is stored. Microsoft recently flip flopped between CFBundleVersion and CFShortBundleVersionString and anyone who depends on accuracy of that string might have been bit.

Not sure I would trust/rely on mdls for anything more than baseline reporting, like "Computer XYZ has an unpatched version of Google Chrome in /Users/jdoe/Desktop/Google Chrome.app", which support teams can rectify.

Users having admin rights, users not adhering to corporate mandates...may as well have a vi vs pico vs nano debate. ¯_(ツ)_/¯

--
https://donmontalvo.com

donmontalvo
Esteemed Contributor III

Circling back to correct my post, er, to admit I was wrong. @tlarkin suggested it isn't fragile, and since trying it, found myself hooked to it. Not a single failure.

--
https://donmontalvo.com

tlarkin
Honored Contributor

Pro tip with mdls use the -raw switch to only output the result and you don't have to awk, grep or sed stuff

joethedsa
Contributor II

Does anyone know what extra command(s) would be added to incorporate this into a script to populate the version of an app as an extension attribute and if it's not installed, to populate "Not Installed"?

tlarkin
Honored Contributor

some Spotlight examples that may or may not help, but I think they are nifty

This just returns anything tagged as an app, its file path, display name and version

mdfind -0 -onlyin /Applications "kMDItemKind == Application" | xargs -0 mdls -name kMDItemPath -name kMDItemDisplayName -name kMDItemVersion

you can get more specific if you wish, like this will use bundle ID to identify Microsoft apps

mdfind -0 -onlyin /Applications "kMDItemKind == Application && kMDItemCFBundleIdentifier = com.microsoft.*" | xargs -0 mdls -name kMDItemPath -name kMDItemDisplayName -name kMDItemVersion

This might be a bit cleaner in Python since you can build dictionary values or deal with structured data sets. You could also pipe this into a associative array in zsh I suppose as well.