On 30/10/2007, Martin Crane <email@hidden> wrote:
> Does anybody else see problems sending an AppleEvents to the 10.5 Finder?
> Specifically, an AppleEvent to move an item to the Trash works fine in
> Tiger, but in Leo Finder returns a coercion error.
The code I have posted to the list in the past works fine for me:
#include <ApplicationServices/ApplicationServices.h>
#include <Carbon/Carbon.h> // for FinderRegistry.h - don't need to
#import <Foundation/Foundation.h>
OSType gFinderSignature = 'MACS';
OSStatus MoveFileToTrash(CFURLRef fileURL) {
AppleEvent event, reply;
OSStatus err;
FSRef fileRef;
AliasHandle fileAlias;
if (CFURLGetFSRef(fileURL, &fileRef) != true)
return coreFoundationUnknownErr;
err = FSNewAliasMinimal(&fileRef, &fileAlias);
if (err == noErr) {
err = AEBuildAppleEvent(kAECoreSuite, kAEDelete,
typeApplSignature,
&gFinderSignature, sizeof(OSType),
kAutoGenerateReturnID,
kAnyTransactionID, &event,
NULL,"'----':alis(@@)", fileAlias);
if (err == noErr) {
err = AESendMessage(&event, &reply,
kAEWaitReply, kAEDefaultTimeout);
if (err == noErr)
AEDisposeDesc(&reply);
AEDisposeDesc(&event);
}
DisposeHandle((Handle)fileAlias);
}
return err;
}
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *path = [[[NSFileManager defaultManager]
currentDirectoryPath] stringByAppendingPathComponent:[NSString
stringWithUTF8String:argv[1]]];
NSURL *url = [NSURL fileURLWithPath:path];
OSStatus err = MoveFileToTrash((CFURLRef)url);
NSLog(@"err: %d", err);
[pool release];
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden
This email sent to email@hidden