(LaunchServices) OS X 10.3 file extensions/mime-types with LaunchServices
(LaunchServices) OS X 10.3 file extensions/mime-types with LaunchServices
- Subject: (LaunchServices) OS X 10.3 file extensions/mime-types with LaunchServices
- From: Jeff Franklin <email@hidden>
- Date: Tue, 9 Dec 2003 14:41:40 -0800 (PST)
This is a message I posted in comp.sys.mac.programmer.help yesterday, I've
submitted it as a bug, but I thought I'd try here in case anyone has any
ideas:
Our unix mail app ports cleanly over to OS X, but we are prevented from
doing proper attachment handling, because unlike most unix flavors, there
are no default mailcap or mime.types files, the *nix way of attributing
file associations for determing which program to open a file of a specific
type.
For OS X, I've stumbled upon the LaunchServices API, the blessed way to
open files. This does most of what I want, and I was pleased to see in
10.3 a way to translate from mime-type to file extension and vice versa
through mechanisms set forth in header file UTType.h. I'm aware of the
"open" command, which would work fine if we didn't care about opening
virus attachments.
I am starting to draw the conclusion that the LaunchServices API is only a
half-baked interface, despite being touted by Apple as the way things
should be done. It finds the correct application for a given MIME-type,
but as for translating between MIME-type and file extension, I have yet to
be successful with that; it behaves as though there were no such mappings.
Some specifics: I've been testing with "image/jpeg" and "image/gif" using
the routines UTTypeCreatePreferredIdentifierForTag and
UTTypeCopyPreferredTagWithClass. For the jpeg case it found identifier
public.jpeg, but the second call was unable to return a file extension.
For the gif case it returned a dynamic identifier, its way of saying that
there was no mapping. I can post code samples if it will help, but I'm
feeling I'm already in over my head.
Is there anyone else currently struggling with this? How does the Finder
get at file extension mappings, and how can I get at these mappings? For
instance, how does "open" know that Preview.app is the way to open a .gif
file? Is there some database somewhere on the system that stores these
mappings? If so, where is it? I know better than to wish for something
like the Windows Registry, but is this the alternative?
TIA. Let me know if there is a better forum to post this to.
Jeff
ps. Here's some more specific information I sent in the bug report
Make the two calls to reproduce:
type_id_ref = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType,
CFSTR("image/jpeg"), NULL);
ext_ref = UTTypeCopyPreferredTagWithClass(type_id_ref,
kUTTagClassFilenameExtension);
In the example above, type_id_ref has string "public.jpeg", as expected,
but ext_ref has string "". I expected ".jpg". Doing the same with
"image/gif" returns type_id_ref string "dyn.....", and ext_ref was NULL.
I expected something like "public.gif", but it seems as though there's no
information for it. Shouldn't Preview.app be seeding this information?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.