I have the following code in a project
NSAppleEventDescriptor *JHCreateAliasDescriptorForURL(NSURL *aURL) {
NSAppleEventDescriptor *retObj = nil;
FSRef fsReference;
if (CFURLGetFSRef((__bridge CFURLRef)aURL, &fsReference)) {
AliasHandle aliasHandle = NULL;
OSStatus err = FSNewAliasMinimal(&fsReference, &aliasHandle);
if (err == noErr && aliasHandle != NULL) {
HLock((Handle)aliasHandle);
retObj = [NSAppleEventDescriptor descriptorWithDescriptorType:typeAlias
data:[NSData dataWithBytes:*aliasHandle
length:GetHandleSize((Handle)aliasHandle)]];
HUnlock((Handle)aliasHandle);
DisposeHandle((Handle)aliasHandle);
}
}
return retObj;
}
It creates an alias descriptor that passes a file to a program that is not applescriptable but responds to this one AppleEvent.
When I compile this under 10.8, I get warnings because all the Carbon FSNewAlias*
functions are deprecated and we're supposed to be using opaque bookmark NSData
objects out of the NSURL
API. However, I've had no luck turning this data into alias AppleEvent descriptors.
How can I make a typeAlias
descriptor in 10.8 without FSNewAlias*
?