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;
26 AEBuildError buildError;
29 if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) {
30 ITDebugLog(@"Error getting PID of application.");
34 berr = AEBuildAppleEvent(evClass, evID, typeProcessSerialNumber,psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, usendString);
35 send = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&sendEvent] autorelease];
36 if (!berr) [send logDesc];
39 ITDebugLog(@"Error: %d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[sendString substringToIndex:buildError.fErrorPos]);
42 err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL);
44 err = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
45 if (resultSize == 0 || err != 0) {
49 AEGetParamDesc(&replyEvent, keyDirectObject, resultType, &resultDesc);
51 recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&resultDesc] autorelease];
52 if (!err) [recv logDesc];
55 ITDebugLog(@"Send Error: %i",err);
60 NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn)
65 NSAppleEventDescriptor *ITSendAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn)
70 AppleEvent event, reply;
71 OSStatus cerr,cerr2,err;
72 NSAppleEventDescriptor *nsd, *nse, *nsr;
73 if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) {
74 ITDebugLog(@"Error getting PID of application.");
77 cerr = AECreateDesc(typeProcessSerialNumber,psn,sizeof(ProcessSerialNumber),&dest);
78 nsd = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&dest] autorelease];
79 cerr2 = AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event);
80 nse = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&event] autorelease];
81 if (!cerr2) [nse logDesc];
82 err = AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
83 nsr = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply] autorelease];
88 @implementation NSAppleEventDescriptor (ITAELogging)
92 AEPrintDescToHandle([self aeDesc],&xx);
93 ITDebugLog(@"AE Descriptor: %s", *xx);