Script to extract data from a plist file

RyanN
New Contributor

I'm new to scripting the MAC OS and looking for some help to gather version info from a plist file. My goal is to create an extension attribute that will use a bash script to tell me if clients have MozyEnterprise installed.

Mozy doesn't seem to install in the typical app directory but installs itself as a system preference. The location to the plist file is /Library/Preferencepanes/MozyEnterprise.prefPane/Contents/info.plist. Within this plist file there is a key named "Get Info string" which is a string type that has a value of "MozyEnterprise 2.13.0 ©2006-2012 Mozy" the version number I'm trying to extract and setup.

Thanks for any help anyone can provide.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

Hi @newporr,
What you want is the defaults command in your script. Defaults has been in OS X since the beginning and pre-dates OS X by quite some time in fact. Its an old Unix process.
Defaults has a "read" command that can read information from plists. In many cases, you can specify the key that you want it to read back. Most times this works, but in some cases, you might need to read back the entire plist contents and then use something like 'grep' or 'awk' to extract just the element(s) you want into a result.

If you look in the Info.plist file from the Mozy Preference Pane, you should see a key in there called either "CFBundleVersion" or" CFBundleShortVersionString", or possibly both. Determine which of those actually has the version string in it you want as your result. Then, in your script do something like this

#!/bin/sh

MozyVersion=$( defaults read /Library/PreferencePanes/MozyEnterprise.prefPane/Contents/info.plist CFBundleShortVersionString )

echo "<result>$MozyVersion</result>"

If you need to change the above to "CFBundleVersion", just edit that last part of the command.

I don't have any version of the Mozy PrefPane installed on my Mac so I can't directly test this out. But see if that gets you what you're looking for.

View solution in original post

2 REPLIES 2

mm2270
Legendary Contributor III

Hi @newporr,
What you want is the defaults command in your script. Defaults has been in OS X since the beginning and pre-dates OS X by quite some time in fact. Its an old Unix process.
Defaults has a "read" command that can read information from plists. In many cases, you can specify the key that you want it to read back. Most times this works, but in some cases, you might need to read back the entire plist contents and then use something like 'grep' or 'awk' to extract just the element(s) you want into a result.

If you look in the Info.plist file from the Mozy Preference Pane, you should see a key in there called either "CFBundleVersion" or" CFBundleShortVersionString", or possibly both. Determine which of those actually has the version string in it you want as your result. Then, in your script do something like this

#!/bin/sh

MozyVersion=$( defaults read /Library/PreferencePanes/MozyEnterprise.prefPane/Contents/info.plist CFBundleShortVersionString )

echo "<result>$MozyVersion</result>"

If you need to change the above to "CFBundleVersion", just edit that last part of the command.

I don't have any version of the Mozy PrefPane installed on my Mac so I can't directly test this out. But see if that gets you what you're looking for.

RyanN
New Contributor

Hi @mm2270,
Thanks for the help with this...I was close but you cleared up a few things for me and it is working great.

Thanks!