Identifying bundles in MacOS X

Brion Vibber brion at pobox.com
Tue Nov 16 09:41:13 CET 2004


Michael J. Fromberger wrote:
> 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.

It's worse than that... the bundle bit _might_ or _might not_ matter, 
since it's not always present, and some extensions are known or not 
or... ugh.

Fortunately, it should be possible to get this information out of Launch 
Services instead of replicating all the same checks: one of the flags 
bit it can return is 'kLSItemInfoIsPackage'. It seems to make the 
correct bundle/not bundle determination in my admittedly limited spot 
checking.

I'm not sure if there's a standard Python module to expose Launch 
Services, but here's a C snippet; use it as you like:

#include <Carbon/Carbon.h>
bool isFilePackage(const char *file) {
     CFStringRef path = CFStringCreateWithCString(
         NULL, file, kCFStringEncodingUTF8);

     CFURLRef url = CFURLCreateWithFileSystemPath(
         NULL, path, kCFURLPOSIXPathStyle, false);
     CFRelease(path);

     LSItemInfoRecord info;
     LSCopyItemInfoForURL(url, kLSRequestAllInfo, &info);
     CFRelease(url);

     return 0 != (info.flags & kLSItemInfoIsPackage);
}

(error checking snipped for brevity)

-- brion vibber (brion @ pobox.com)



More information about the Python-list mailing list