Posted on 12-04-2015 12:26 PM
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.
Solved! Go to Solution.
Posted on 12-04-2015 12:35 PM
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"
Posted on 12-04-2015 12:36 PM
mdls -name kMDItemVersion /Applications/Microsoft Word.app
This would give the version number, would this work?
Mike beat me to it.
Posted on 12-04-2015 12:35 PM
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"
Posted on 12-04-2015 12:36 PM
mdls -name kMDItemVersion /Applications/Microsoft Word.app
This would give the version number, would this work?
Mike beat me to it.
Posted on 12-04-2015 12:48 PM
This is perfect! Thanks for the quick response guys!
Posted on 12-06-2015 06:49 PM
Isn't casper supposed to help you not need to deploy scripts to do this kinda stuff?
Posted on 10-14-2016 07:34 AM
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.
Posted on 10-14-2016 08:19 AM
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. ¯_(ツ)_/¯
Posted on 05-11-2020 05:38 PM
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.
Posted on 05-26-2020 06:35 PM
Pro tip with mdls
use the -raw
switch to only output the result and you don't have to awk
, grep
or sed
stuff
Posted on 07-06-2020 08:23 AM
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"?
Posted on 07-06-2020 05:19 PM
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.