470,600 Members | 1,466 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,600 developers. It's quick & easy.

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.
Jun 27 '08 #1
3 1806
you need appscript "that allows you to control scriptable Mac OS X
applications from Python"
http://pypi.python.org/pypi/appscript/0.18.1
Jun 27 '08 #2
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.

?
ma***********@gmail.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
Jun 27 '08 #3
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 <mi*********@gmail.com>
http://pythonwise.blogspot.com
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul | last post: by
6 posts views Thread by D. Yates | last post: by
reply views Thread by ev951 | last post: by
6 posts views Thread by Zytan | last post: by
4 posts views Thread by Bob Altman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.