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;
24 AEBuildError buildError;
27 if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) {
28 ITDebugLog(@"Error getting PID of application.");
32 berr = AEBuildAppleEvent(evClass, evID, typeProcessSerialNumber,psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, usendString);
33 send = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&sendEvent] autorelease];
34 if (!berr) [send logDesc];
37 ITDebugLog(@"Error: %d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[sendString substringToIndex:buildError.fErrorPos]);
40 err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, NULL, NULL);
42 err = AEGetNthDesc(&replyEvent, 1, typeWildCard, nil, &nthDesc);
43 if (!err) ITDebugLog(@"Error getting Nth desc.");
45 recv = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&nthDesc] autorelease];
46 if (!err) [recv logDesc];
49 ITDebugLog(@"Send Error: %i",err);
54 NSAppleEventDescriptor *ITSendAEWithKey(FourCharCode reqKey, FourCharCode evClass, FourCharCode evID,const ProcessSerialNumber *psn)
59 NSAppleEventDescriptor *ITSendAE(FourCharCode eClass, FourCharCode eID,const ProcessSerialNumber *psn)
64 AppleEvent event, reply;
65 OSStatus cerr,cerr2,err;
66 NSAppleEventDescriptor *nsd, *nse, *nsr;
67 if ((GetProcessPID(psn, &pid) == noErr) && (pid == 0)) {
68 ITDebugLog(@"Error getting PID of application.");
71 cerr = AECreateDesc(typeProcessSerialNumber,psn,sizeof(ProcessSerialNumber),&dest);
72 nsd = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&dest] autorelease];
73 cerr2 = AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event);
74 nse = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&event] autorelease];
75 if (!cerr2) [nse logDesc];
76 err = AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
77 nsr = [[[NSAppleEventDescriptor alloc] initWithAEDescNoCopy:&reply] autorelease];
82 @implementation NSAppleEventDescriptor (ITAELogging)
86 AEPrintDescToHandle([self aeDesc],&xx);
87 ITDebugLog(@"AE Descriptor: %s", *xx);