A command for finding an application's version number?

Hello,


I need a command for finding the version number of a specific application installed in OS X, and I need to be able to run it via the UNIX feature of Apple Remote Desktop, so that I can run it on hundreds of computers. First I tried this:


system_profiler -detailLevel full


It works, but it takes a long time to produce the output, because it's gathering and outputting all of the information that System Profiler provides. I don't know if there's a way to narrow it down so that it only gives me the version number of the specific application I need to know about. This is an example of what the output looks like for each application listed.


iPhoto:


Version: 9.2.1

Last Modified: 10/27/11 10:05 AM

Kind: Intel

64-Bit (Intel): No

App Store: No

Location: /Applications/iPhoto.app


Copying that to TextEdit and searching for the application's name takes way too long, especially for hundreds of computers. Are there any arguments or regular expressions I could add to the command to narrow it down, and make it only output the information I need?


Someone suggested this command, which takes the information from Spotlight:


mdls -name kMDItemVersion <path to file>


That works for apps in the Applications folder, but the application I need the version number for is in the /usr/bin folder and I'm guessing that's not indexed by Spotlight, because it returns:


kMDItemVersion = (null)


Any help would be greatly appreciated!


-Mike

Posted on Nov 1, 2011 8:56 AM

Reply
9 replies

Nov 1, 2011 11:48 AM in response to red_menace

You rock! I'm definitely on the right track now. Yes, it's a regular application package, not a UNIX executable. Ok, so I use this command to display the Info.plist file inside that package:


cat /usr/bin/uc/UndercoverRegistration.app/Contents/Info.plist


And it outputs this:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>CFBundleDevelopmentRegion</key>

<string>English</string>

<key>CFBundleExecutable</key>

<string>UndercoverRegistration</string>

<key>CFBundleIconFile</key>

<string>Undercover</string>

<key>CFBundleIdentifier</key>

<string>com.orbicule.UndercoverRegistration</string>

<key>CFBundleInfoDictionaryVersion</key>

<string>6.0</string>

<key>CFBundlePackageType</key>

<string>APPL</string>

<key>CFBundleShortVersionString</key>

<string>4.5</string>

<key>CFBundleSignature</key>

<string>????</string>

<key>CFBundleVersion</key>

<string>4.5</string>

<key>NSMainNibFile</key>

<string>MainMenu</string>

<key>NSPrincipalClass</key>

<string>NSApplication</string>

</dict>

</plist>


So can I add arguments to that command to have it only display the version number, which is on line 18 (the value is 4.5 here)? So would I be able to display only line 18, or display whatever is below the line that reads "<key>CFBundleShortVersionString</key>"? Thanks!

Nov 1, 2011 12:16 PM in response to ITdept012

You can't rely on the line number because that's going to be different for just about every application, depending on what data they put in their info.plist.


However, there are a number of other utilities that might be relevant. grep comes to mind:


grep -A1 CFBundleShortVersionString /usr/bin/uc/UndercoverRegistration.app/Contents/Info.plist


or maybe something that can parse the XML.

Nov 1, 2011 1:15 PM in response to ITdept012

The defaults command has been a part of the standard installation for quite a while now, although the defaults man page says it "will be changed in an upcoming major release to only operate on preferences domains". At that time some other tool will need to be used, but currently (as of Lion 10.7.2) you can still use defaults to specify any plist file. In that case, using your example, you can also do something like (note that the .plist extension is omitted):

defaults read /usr/bin/uc/UndercoverRegistration.app/Contents/Info CFBundleShortVersionString

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

A command for finding an application's version number?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.