Re: LSGetApplicationForItem -or- my crazy adventure with launch services
Re: LSGetApplicationForItem -or- my crazy adventure with launch services
- Subject: Re: LSGetApplicationForItem -or- my crazy adventure with launch services
- From: Douglas Davidson <email@hidden>
- Date: Thu, 6 Sep 2001 09:00:51 -0700
On Wednesday, September 5, 2001, at 11:11 PM, email@hidden wrote:
[opensWithField setStringValue:(NSString
*)LSGetApplicationForItem(&ref, kLSRolesAll, NULL, NULL)];
LSGetApplicationForItem doesn't return a string. It returns an
OSStatus, i.e. a numeric error code. This is standard practice for Mac
toolbox calls (as it is for many BSD calls). You should check this
return value.
The real output from the function is returned by reference in the fourth
argument (if you want a CFURLRef, which you probably do) or in the third
argument (if you want an FSRef, which you probably don't). The CFURLRef
that you get can be cast into an NSURL, then you can use the path method
to get a string corresponding to its path. I believe you do get a
reference to the CFURLRef.
There is also LSGetApplicationForURL, which will do the same thing
without requiring conversion to an FSRef--it takes a CFURLRef or NSURL
instead.
However, none of this is actually necessary, since -[NSWorkspace
getInfoForFile:application:type:] will do the same thing for you,
returning an autoreleased string by reference in the second argument.
Douglas Davidson