Identifying bundles in MacOS X
Michael J. Fromberger
Michael.J.Fromberger at Clothing.Dartmouth.EDU
Mon Nov 15 23:14:44 EST 2004
In article <2vt7veF2nues7U1 at uni-berlin.de>,
Greg Ewing <greg at cosc.canterbury.ac.nz> wrote:
> Michael J. Fromberger wrote:
> > Given the pathname of a directory in my filesystem, I would like a
> > graceful way to determine whether or not that directory represents
> > a "bundle", in the sense that, when you double-click on the
> > directory's icon in the Finder, it is launched rather than "opened"
> > for viewing. Applications behave this way by default, but so do
> > various other file types (e.g., the "rtfd" files created by
> > TextEdit, and the data files for certain applications such as
> > Quicken).
>
> I think that a MacOSX-style application can be recognised simply by
> the fact that it's a directory whose name ends in ".app". (You don't
> usually see that extension in the Finder, but all MacOSX application
> bundles seem to have it.)
Actually, Apple's developer documentation seems to imply that there is a
"bundle bit" in the Finder info (or possibly the extended Finder info)
for directories, and that if this bit is set, the Finder will treat the
folder as a bundle. At any rate, there are many bundle-like directories
other than just ".app" files and old-style 'APPL' type files. The
trouble is, the Carbon.File module does not seem to expose the
appropriate fields of the FSCatalogInfo structure from the Carbon API,
so I can't get at that bit from within Python.
I found and adapted a patch to Mac/Modules/file/_Filemodule.c, that
makes the finderInfo and finderXInfo fields visible, but either I did it
wrongly, or there is some other issue I've missed, for I get nothing but
an empty FInfo structure back when I try to access either of them.
I guess my next step should be to write a C program against the Carbon
API, and see if I can get the information that way -- if so, I guess I
will just have to patch the Carbon.File module myself. If not, I might
have to admit defeat for now.
Meanwhile, I'm using a workaround, a.k.a. a gross hack: If the
directory's name has one of a set of "known" extensions, or if it
contains a directory named "Contents", and if it doesn't have more than
a few files at its top level apart from the "Contents" directory, I'm
considering it a bundle. That works well enough for my purposes, but
I'd really rather have it work "correctly."
Thanks for taking the time to write back!
Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
More information about the Python-list
mailing list