Hello J,

> Does anyone know how to get the version of an application on OS X (i.e.
> the version string that appears in the "Version" field in the "Get Info"
> window for an application)?
>
> I'm running OS 10.4.11, python 2.5.

#!/usr/bin/env python

from xml.etree.cElementTree import iterparse
from os.path import isfile

def get_version(app):
    info_file = "/Applications/%s.app/Contents/Info.plist" % app
    if not isfile(info_file):
        raise KeyError("No version file found")

    get = 0
    for event, element in iterparse(open(info_file)):
        if get:
            return element.text

        if (element.tag == "key") and (element.text ==
"CFBundleVersion"):
            get = 1

    raise KeyError("Can't find CFBundleVersion key")

if __name__ == "__main__":
    from sys import argv

    print get_version(argv[1])

HTH,
--
Miki <[EMAIL PROTECTED]>
http://pythonwise.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to