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)
53 NSAppleEventDescriptor *ITSendPlainAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn)
58 AppleEvent event, reply;
59 OSStatus cerr,cerr2,err;
60 NSAppleEventDescriptor *nsd, *nse, *nsr;
61 if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
62 ITDebugLog(@"Error getting PID of application.");
65 cerr = AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest);
66 nsd = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&dest] autorelease];
67 cerr2 = AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event);
68 nse = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&event] autorelease];
69 if (!cerr2) [nse logDesc];
70 err = AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
71 nsr = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply] autorelease];
76 @implementation NSAppleEventDescriptor (ITAELogging)
80 AEPrintDescToHandle([self aeDesc],&xx);
81 ITDebugLog(@"AE Descriptor: %s", *xx);