Re: path name from Apple Event
Re: path name from Apple Event
- Subject: Re: path name from Apple Event
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Mon, 15 Aug 2005 17:37:10 +0200
On 15.08.2005, at 09:18, email@hidden wrote:
Given an NSAppleEventDescriptor of typeAlias = 'alis' - how do I get
the path as an NSString?
Thanks to help from the list and private communications I finally got
my path name - at least on Panther.
Here is my code (all error handling removed) - suggestions for
improvements are welcome:
// NSAppleEventDescriptor *event has class kCoreEventClass = 'aevt' and
id kAEOpenDocuments = 'odoc'
NSAppleEventDescriptor *dirctObj = [ event descriptorForKeyword:
keyDirectObject ];
NSAppleEventDescriptor *aliasED = [ dirctObj descriptorAtIndex: 1 ];
NSData *data = [ aliasED data ];
unsigned int len = [data length];
void *bytes = malloc( len );
[ data getBytes: bytes ];
AliasPtr aliasPtr = bytes ;
AliasHandle aliasHandle = &aliasPtr ;
FSRef fsRef ;
Boolean wasChanged;
OSErr k2 = FSResolveAliasWithMountFlags( NULL, aliasHandle, &fsRef,
&wasChanged, kResolveAliasFileNoUI );
// Note: k2 = noErr on Panther, k2 = paramErr on Tiger.
free( bytes );
CFURLRef resolvedUrl = CFURLCreateFromFSRef(NULL, &fsRef);
NSString *resolvedPath = (NSString*) CFURLCopyFileSystemPath(
resolvedUrl, kCFURLPOSIXPathStyle);
CFRelease(resolvedUrl);
[ resolvedPath autorelease ];
This works fine on Panther (10.3.9) but the
FSResolveAliasWithMountFlags() returns paramErr on Tiger (10.4.1).
The Tiger alias data looks ok (but cannot be directly compared because
it contains the name of the disk, which is different on my two
computers).
So now another question: How do I get my pathname on Tiger?
Kind regards,
Gerriet.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden