Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have bash script which was written for OS X and now ported to Linux. I don't have access to the Linux box. The bash script would read values from plist files using the defaults read and PlistBuddy command available on OS X.

Since the Linux machine doesn't have these commands, I'm looking for workarounds. Is there library/script (Perl preferably) that helps user fetch values from plist files for a given key on a Linux machine?

I tried using sed/awk, but the output isn't reliable. I've come across scripts like plutil.pl that convert a plist file to other formats.

I have installed a Virtual machine running Ubuntu on my Mac so that I can test my changes before deploying to the actual Linux box.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Since .plist files are already XML (or can be easily converted) you just need something to decode the XML.

For that use xml2:

$ cat com.apple.systemsound.plist
<?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>com.apple.sound.beep.volume</key>
    <real>1</real>
</dict>
</plist>
$ xml2 < com.apple.systemsound.plist
/plist/@version=1.0
/plist/dict/key=com.apple.sound.beep.volume
/plist/dict/real=1
$ 

You should be able to figure out the rest.

Or for Perl, use XML::Simple; (see perldoc for more) to put the XML data structure into a hash.

share|improve this answer

libplist seems to meet your requirements. There is a Ubuntu package name "libplist-utils" that you could reference in your script:

Description-en: Apple property list converter This package containt tools to convert Apple property list files from binary to XML and vice-versa. It's part of the libimobiledevice stack, providing access to iDevices (iPod, iPhone, iPad ...).

Homepage: http://www.libimobiledevice.org/

Install command:

apt-get install libplist-utils
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com?utm_source=stackoverflow.com&amp;utm_medium=site-ui&amp;utm_campaign=footerlink\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2014 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>                   with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2014.11.21.2038\r\n            </div>\r\n                <div id=\"additional-notices\">\r\n                    Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group. <br>This site is not affiliated with Linus Torvalds or The Open Group in a"], "copyright__copyright__copyright": ["ge containt tools to convert Apple property list files from binary to XML and vice-versa. It's part of the libimobiledevice stack, providing access to iDevices (iPod, iPhone, iPad ...).\n\nHomepage: http://www.libimobiledevice.org/\n\nInstall command:\n\napt-get install libplist-utils\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}