Skip to main content
Solved

Script to extract data from a plist file


Forum|alt.badge.img+6
  • New Contributor
  • 6 replies

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.

Best answer by mm2270

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 original
Did this topic help you find an answer to your question?

2 replies

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • May 8, 2014

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.


Forum|alt.badge.img+6
  • Author
  • New Contributor
  • 6 replies
  • May 12, 2014

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!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings