[Pythonmac-SIG] obtaining versions of application bundles
Bob Ippolito
bob at redivi.com
Fri Oct 22 02:08:49 CEST 2004
On Oct 21, 2004, at 20:00, brad.allen at omsdal.com wrote:
> I'm looking for a good way to obtain the versions of Mac OS X
> application
> bundles. The osascript/Applescript approach has serious problems,
> because
> sometimes the Finder isn't running.
>
> The info.plist file in the application bundle usually contains version
> info. However, I'm not sure I want to get into parsing plists. Is this
> the
> best approach, or is there a way to do it using native APIs?
>
> Thanks for any help or ideas on this!
>
> (here is my test attempt to obtain a version of an application bundle
> using
> the Applescript approach--various bad things happened when run via ssh
> on a
> Mac sitting at the login prompt)
>
> import subprocess
>
> #determine the version of Timbuktu, as an example
> appleScript = """
> tell application "Finder"
> version of file "Applications:Timbuktu Pro:Timbuktu Pro" of
> startup
> disk
> end tell
> """
>
> PIPE = subprocess.PIPE
> args = ('osascript','-e',appleScript)
> child =
> subprocess.Popen(args,executable='/usr/bin/
> osascript',stdin=PIPE,stdout=PIPE,stderr=PIPE)
> version = child.stdout.read()
> print version
(note that neither of these approaches will work for CFM applications
that are not an application bundle.. you would need to read the
resource fork and get the plist resource.. I think it's 'plst',..)
With PyObjC:
>>> from Foundation import *
>>> bndl = NSBundle.bundleWithPath_(u'/Applications/iTunes.app')
>>> bndl.infoDictionary()[u'CFBundleVersion']
u'4.6'
Without:
>>> import plistlib
>>>
plistlib.Plist.fromFile(u'/Applications/iTunes.app/Contents/
Info.plist')[u'CFBundleVersion']
'4.6'
Finding an application if you don't know its path more or less requires
using LaunchServices.. which isn't included with Python 2.3 (but I
think you can get it from Jack's PackageManager repository, and I
believe appscript may also install it).
-bob
More information about the Pythonmac-SIG
mailing list