Re: path name from Apple Event
Re: path name from Apple Event
- Subject: Re: path name from Apple Event
- From: Bill Monk <email@hidden>
- Date: Mon, 15 Aug 2005 09:21:14 -0500
Gerriet M. Denkmann wrote:
Given an NSAppleEventDescriptor of typeAlias = 'alis' - how do I get
the path as an NSString?
Coerce typeAlias to typeFileURL, which is an HFS-style colon-
delimited pathname.
The use CFURLto get a slash-delimited pathname as an NSString.
Below is a method to do the job.
Regards,
Bill Monk
-(NSString *)posixPathFromAliasDesc:(NSAppleEventDescriptor *)aliasDesc
{
CFStringRef posixPath = NULL;
// coerce typeAlias to typeFileURL, a colon-delimited HFS-style
pathname
NSAppleEventDescriptor *urlDesc = [aliasDesc
coerceToDescriptorType:typeFileURL];
NSString *hfsPath = [urlDesc stringValue];
// make CFURL from HFS path
BOOL isHFSDirectoryPath = [hfsPath hasSuffix:@":"];
CFURLRef myURLRef = CFURLCreateWithFileSystemPath
( kCFAllocatorDefault,
(CFStringRef)
hfsPath ,
kCFURLHFSPathStyle,
isHFSDirectoryPath );
if (NULL != myURLRef) {
// make POSIX path from CFURL
posixPath = CFURLCopyFileSystemPath( myURLRef,
kCFURLPOSIXPathStyle );
CFRelease( myURLRef );
if (NULL != posixPath) {
[(NSString *)posixPath autorelease];
}
}
return (NSString *)posixPath;
}
_______________________________________________
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