473,287 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Identifying bundles in MacOS X

Greetings,

The following question pertains to a problem I am solving in Python
2.4b2 on a MacOS 10 (Panther) system with an HFS+ filesystem.

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).

So, what I want is the following: A function I can call which will,
given a pathname, return True if the corresponding directory has that
property, and False otherwise. So far, I'm stumped. Can anyone help?

Here are the things I've tried so far:

I found the Carbon.File module, and tried what I thought was the obvious
thing:

from Carbon import File

fss = File.FSSpec(dir_path)
info = fss.FSpGetFInfo()

This, unfortunately, does not seem to work for directories; an OSError
is raised (-43, File Not Found). I investigated on Apple's developer
site, and it seems this is the expected behaviour. So, no fault of
Python there.

Next, I tried the following:

from Carbon import Files

fsr = File.FSRef(dir_path)
cat_info = fsr.FSGetCatalogInfo(Files.kFSCatInfoFinderInfo)

This works, but now I have no idea how to determine the answer to my
question. The value of cat_info is a tuple consisting of:

- a File.FSCatalogInfo object
- a Unicode string (the name of the directory)
- a File.FSSpec object
- a File.FSRef object

According to [1], the FSCatalogInfo structure has finderInfo and
extFinderInfo fields, which ought to contain what I'm after (I think),
but these do not appear to be exposed by the FSCatalogInfo class in the
Carbon.File library, even if I specify I want the Finder info and
extended Finder info when I call FSGetCatalogInfo().

All right, so now my questions for those of you who know better than I
do, are these:

1. Am I looking in the right place for this information?

2. If not, is there a preferred method for determining whether
a given directory represents a "bundle" in the MacOS sense?

I would be most grateful for any helpful advice you might be able to
lend me regarding this puzzle.

Thanks,
-M

P.S.- I was disconcerted to discover that the Python documentation
does not seem to list the Carbon.File module. The macfs module
is listed, but it is deprecated, so I would prefer not to use it
in new code.

References:
[1] Carbon API documentation, "FSCatalogInfo"
http://shorl.com/biginegastuni

--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
Jul 18 '05 #1
4 2049
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.)

A Classic-style application is a file with a type code
of "APPL".

As for other files, they can be associated with applications
using either the old type/creator code system, or the new
filename-extension-based system (which is disappointingly
Windows-like, but sadly seems to be the dictated Way of
the Future :-(.)

The type and creator of a file can be found using FSpGetInfo.
You're right that this doesn't work for directories, but
directories don't have type/creator codes anyway. MacOSX
bundles seem to be recognised purely by filename suffix
(and possibly also by having the right internal structure).

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg

Jul 18 '05 #2
In article <2v*************@uni-berlin.de>,
Greg Ewing <gr**@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
Jul 18 '05 #3
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)
Jul 18 '05 #4
In article <2v*************@uni-berlin.de>,
Brion Vibber <br***@pobox.com> wrote:
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.


The plot thickens!
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:
[...]


Thank you very much for your advice, and for the sample code -- I will
play around with this snippet, and see I can get what I need. It looks
promising! If it works out, it will not be so difficult to add it as an
extension module.

Cheers,
-M
--
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eric | last post by:
I am attempting to install the Zend Studio Server on a normal installation of MacOS X 10.2.8. I have downloaded ZendStudioServer-3.0.0a-Darwin-ppc (evaluation copy) and have gotten part way...
1
by: Daniel | last post by:
Hello I am developing a Java application for MacOS X, Windows and Linux. So far easy with Java. But when it comes to file types, the platfrom-specific handling knocks my application-created...
0
by: Javier Vazquez | last post by:
Hi Pardon me for being a newbie, but how do I install JMF on MacOS X? Does anyone know a website with a nice howto? I had no problem installing and running JMF on Windows, because Sun...
1
by: Han-Wen Nienhuys | last post by:
Hi there, this might not be the right group to ask, but I'm looking for some hints on making a drag & droppable application on MacOS X. I succeeded in producing a bundle that calls a python...
2
by: donbro | last post by:
If my read of the extension source (Mac/Modules/file/_Filemodule.c) is correct, the parameter sizes specified for data and resource file sizes are UInt32 where they should be UInt64. In both OS9...
0
by: Jerry LeVan | last post by:
Here is how I spent the last couple of days... Using aqua tcl/tk with postgresql seems to take a bit of extra work. With clues from Dan Steffen, I think I have it working... Here is the...
17
by: Jim Strickland | last post by:
We currently are running a data intensive web service on a Mac using 4D. The developers of our site are looking at converting this web service to PostgreSQL. We will have a backup of our three...
0
by: skip | last post by:
The thread John Nagle started about building Python 2.5 on Fedora Core 6 led me to implement a slight change to Python's setup.py. You clearly can't have the build stop if the bits needed to build...
0
by: Mathieu Prevot | last post by:
2008/9/24 Jaime Huerta Cepas <jhuerta@cipf.es>: IMHO this is too complex to commit. Macport is a way to do what you want, but packages may not be up to date enough. Maybe the easiest and...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.