How to get the version of a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J Wilson

    #1

    How to get the version of a file

    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.
  • martin.laloux@gmail.com

    #2
    Re: How to get the version of a file

    you need appscript "that allows you to control scriptable Mac OS X
    applications from Python"
    http://pypi.python.org/pypi/appscript/0.18.1

    Comment

    • J Wilson

      #3
      Re: How to get the version of a file

      I'm not clear on how to use this to read the version resource.
      Specially, I need to get the version of Palm Conduit, which is, I guess,
      a "carbonized " shared library... or something.

      ?


      martin.laloux@g mail.com wrote:
      you need appscript "that allows you to control scriptable Mac OS X
      applications from Python"
      http://pypi.python.org/pypi/appscript/0.18.1

      Comment

      • Miki

        #4
        Re: How to get the version of a file

        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.cElem entTree import iterparse
        from os.path import isfile

        def get_version(app ):
        info_file = "/Applications/%s.app/Contents/Info.plist" % app
        if not isfile(info_fil e):
        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 ==
        "CFBundleVersio n"):
        get = 1

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

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

        print get_version(arg v[1])

        HTH,
        --
        Miki <miki.tebeka@gm ail.com>
        If it won't be simple, it simply won't be. [Hire me, source code]

        Comment

        Working...