Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return app version in terminal on osx

Tags:

terminal

macos

I am needing to use app version in a .sh script on Mac osX 10.10 so that I can do a compare to another number so I can force an update or not.

So far I have this (I am using Firefox.app as an example)

FirefoxmdlsVersion= mdls -name kMDItemVersion /Applications/Firefox.app;
echo $FirefoxmdlsVersion

This returns kMDItemVersion = "34.0"which is a step in the right direction but I need just the number so that I can do my compare example 340

Here is what I have attempted to do with a new variable but I dont get an error or output at all

FFV2=${FirefoxmdlsVersion//'kMDItemVersion ='}
FFV3=${FirefoxmdlsVersion:18:4}

I maybe going in the wrong direction here, but Ive looked a post and havent made any progress. Can anyone help me?

like image 223
ShawnIT Avatar asked Dec 22 '14 01:12

ShawnIT


2 Answers

To add one more option to the list, you can also use the defaults tool.

For example:

defaults read /Applications/Firefox.app/Contents/Info.plist CFBundleShortVersionString

Will output the value of the CFBundleShortVersionString entry from Firefox's Info.plist file, e.g.: 74.0

I prefer to use the defaults command because there are no preconditions to using it and the command is very simple.

like image 94
Benjamin Avatar answered Sep 18 '22 17:09

Benjamin


If you have Xcode and the developer tools installed, you can always use PlistBuddy...

For example:

/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" /Applications/TextEdit.app/Contents/Info.plist

gives me back the version number of "1.10" under Yosemite.

The Info.plist file of any app usually has a version under the "CFBundleShortVersionString" key.

like image 20
Michael Dautermann Avatar answered Sep 21 '22 17:09

Michael Dautermann