5 * Created by Alexander Strange on Wed Feb 11 2004.
6 * Copyright (c) 2004 __MyCompanyName__. All rights reserved.
11 #import "ITAppleEventTools.h"
13 NSAppleEventDescriptor *ITSendAEWithString(NSString *sendString, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn)
15 //Add error checking...
18 const char *usendString = [sendString UTF8String];
20 AppleEvent sendEvent, replyEvent;
21 NSAppleEventDescriptor *send, *recv;
23 AEBuildError buildError;
26 if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) {
27 ITDebugLog(@"Error getting PID of application.");
31 berr = AEBuildAppleEvent(evClass, evID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, usendString);
32 send = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&sendEvent] autorelease];
33 if (!berr) [send logDesc];
36 ITDebugLog(@"Error: %d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[sendString substringToIndex:buildError.fErrorPos]);
39 err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL);
40 recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&replyEvent] autorelease];
41 if (!err) [recv logDesc];
44 ITDebugLog(@"Send Error: %i",err);
49 NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn)
54 NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn)
59 AppleEvent event, reply;
60 OSStatus cerr,cerr2,err;
61 NSAppleEventDescriptor *nsd, *nse, *nsr;
62 if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) {
63 ITDebugLog(@"Error getting PID of application.");
66 cerr = AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest);
67 nsd = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&dest] autorelease];
68 cerr2 = AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event);
69 nse = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&event] autorelease];
70 if (!cerr2) [nse logDesc];
71 err = AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
72 nsr = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply] autorelease];
77 @implementation NSAppleEventDescriptor (ITAELogging)
81 AEPrintDescToHandle([self aeDesc],&xx);
82 ITDebugLog(@"AE Descriptor: %s", *xx);