No more Desc printing! :)
[ITFoundation.git] / ITAppleEventCenter.m
1 #import "ITAppleEventCenter.h"
2
3 Boolean MyAEIdleCallback (
4                                          EventRecord * theEvent,
5                                          SInt32 * sleepTime,
6                                          RgnHandle * mouseRgn
7                                          );
8
9 Boolean MyAEIdleCallback (
10                                          EventRecord * theEvent,
11                                          SInt32 * sleepTime,
12                                          RgnHandle * mouseRgn
13                                          )
14 {
15     return FALSE;
16 }
17
18 @implementation ITAppleEventCenter
19
20 static ITAppleEventCenter *_sharedAECenter = nil;
21
22 + (id)sharedCenter
23 {
24     if( _sharedAECenter ) {
25         return _sharedAECenter;
26     } else {
27         return _sharedAECenter = [[ITAppleEventCenter alloc] init];
28     }
29 }
30
31 - (id)init
32 {
33     if (self = [super init])
34            {
35            idleUPP = NewAEIdleUPP(MyAEIdleCallback);
36            }
37     return self;
38 }
39
40 - (void)dealloc
41 {
42     DisposeAEIdleUPP(idleUPP);
43 }
44
45 - (NSString*)sendAEWithRequestedKey:(NSString*)key eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
46 {
47     //Add error checking...
48     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
49     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
50
51     NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('%s'), from:'null'() }", [key UTF8String]];
52     const char *sendString = [nssendString UTF8String];
53     NSString  *_finalString = nil;
54
55     AppleEvent sendEvent, replyEvent;
56
57     DescType resultType;
58     Size resultSize, charResultSize;
59
60     AEBuildError buildError;
61     OSStatus err;
62     OSErr err2, err3;
63     /*
64         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
65             //NSLog(@"Error getting PID of application! Exiting.");
66             return nil;
67         }
68         */
69     //NSLog(@"_sendString: %s", sendString);
70
71     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
72
73     //[self printCarbonDesc:&sendEvent];
74
75     if (err) {
76         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]);
77     }
78
79     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
80
81     //[self printCarbonDesc:&replyEvent];
82
83     if (err) {
84         //NSLog(@"Send Error: %i",err);
85     } else {
86         unichar *result = 0;
87
88         err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
89         result = malloc(resultSize);
90
91         if (err2) {
92             //NSLog(@"Error After AESizeOfParam: %i", err2);
93         } else {
94             err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, result, resultSize, &charResultSize);
95
96             if (err3) {
97                 //NSLog(@"Error After AEGetParamPtr: %i", err3);
98             } else {
99                 _finalString = [NSString stringWithCharacters:result length:charResultSize/sizeof(unichar)];
100             }
101         }
102         free(result);
103     }
104
105     AEDisposeDesc(&sendEvent);
106     AEDisposeDesc(&replyEvent);
107
108     return _finalString;
109 }
110
111 - (NSString*)sendAEWithSendString:(NSString*)nssendString eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
112 {
113     //Add error checking...
114     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
115     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
116
117     const char *sendString = [nssendString UTF8String];
118     NSString  *_finalString = nil;
119
120     AppleEvent sendEvent, replyEvent;
121
122     DescType resultType;
123     Size resultSize, charResultSize;
124
125     AEBuildError buildError;
126     OSStatus err;
127     OSErr err2, err3;
128     /*
129         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
130             //NSLog(@"Error getting PID of application! Exiting.");
131             return nil;
132         }
133         */
134     //NSLog(@"_sendString: %s", sendString);
135
136     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
137
138     //[self printCarbonDesc:&sendEvent];
139
140     if (err) {
141         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]);
142     }
143
144     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
145
146     //[self printCarbonDesc:&replyEvent];
147
148     if (err) {
149         //NSLog(@"Send Error: %i",err);
150     } else {
151         unichar *result = 0;
152
153         err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
154         result = malloc(resultSize);
155
156         if (err2) {
157             //NSLog(@"Error After AESizeOfParam: %i", err2);
158         } else {
159             err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, result, resultSize, &charResultSize);
160
161             if (err3) {
162                 //NSLog(@"Error After AEGetParamPtr: %i", err3);
163             } else {
164                 _finalString = [NSString stringWithCharacters:result length:charResultSize/sizeof(unichar)];
165             }
166         }
167         free(result);
168     }
169
170     AEDisposeDesc(&sendEvent);
171     AEDisposeDesc(&replyEvent);
172
173     return _finalString;
174 }
175
176 - (long)sendAEWithRequestedKeyForNumber:(NSString*)key eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
177 {
178     //Add error checking...
179     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
180     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
181
182     NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('%s'), from:'null'() }", [key UTF8String]];
183     const char *sendString = [nssendString UTF8String];
184     long result = 0;
185
186     AppleEvent sendEvent, replyEvent;
187
188     DescType resultType;
189     Size resultSize, charResultSize;
190
191     AEBuildError buildError;
192     OSStatus err;
193     OSErr err2, err3;
194     /*
195         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
196             //NSLog(@"Error getting PID of application! Exiting.");
197             return nil;
198         }
199         */
200     //NSLog(@"_sendString: %s", sendString);
201
202     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
203
204     //[self printCarbonDesc:&sendEvent];
205
206     if (err) {
207         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]);
208     }
209
210     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
211
212     //[self printCarbonDesc:&replyEvent];
213
214     if (err) {
215         //NSLog(@"Send Error: %i",err);
216     } else {
217         err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
218
219         if (err2) {
220             //NSLog(@"Error After AESizeOfParam: %i", err2);
221         } else {
222             err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, &result, resultSize, &charResultSize);
223
224             if (err3) {
225                 //NSLog(@"Error After AEGetParamPtr: %i", err3);
226             }
227         }
228     }
229
230     AEDisposeDesc(&sendEvent);
231     AEDisposeDesc(&replyEvent);
232
233     return result;
234 }
235
236 - (NSString*)sendTwoTierAEWithRequestedKey:(NSString*)key fromObjectByKey:(NSString*)object eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
237 {
238     //Add error checking...
239     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
240     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
241
242     NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('%s'), from:obj { form:'prop', want:type('prop'), seld:type('%s'), from:'null'() } }", [key UTF8String], [object UTF8String]];
243     const char *sendString = [nssendString UTF8String];
244     NSString  *_finalString = nil;
245
246     AppleEvent sendEvent, replyEvent;
247
248     DescType resultType;
249     Size resultSize, charResultSize;
250
251     AEBuildError buildError;
252     OSStatus err;
253     OSErr err2, err3;
254     /*
255         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
256             //NSLog(@"Error getting PID of application! Exiting.");
257             return nil;
258         }*/
259
260     //NSLog(@"_sendString: %s", sendString);
261
262     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
263
264     //[self printCarbonDesc:&sendEvent];
265
266     if (err) {
267         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]);
268     }
269
270     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
271
272     //[self printCarbonDesc:&replyEvent];
273
274     if (err) {
275         //NSLog(@"Send Error: %i",err);
276     } else {
277         unichar *result = 0;
278
279         err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
280         result = malloc(resultSize);
281
282         if (err2) {
283             //NSLog(@"Error After AESizeOfParam: %i", err2);
284         } else {
285             err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, result, resultSize, &charResultSize);
286
287             if (err3) {
288                 //NSLog(@"Error After AEGetParamPtr: %i", err3);
289             } else {
290                 _finalString = [NSString stringWithCharacters:result length:charResultSize/sizeof(unichar)];
291             }
292         }
293         free(result);
294     }
295
296     AEDisposeDesc(&sendEvent);
297     AEDisposeDesc(&replyEvent);
298
299     return _finalString;
300 }
301
302 - (long)sendTwoTierAEWithRequestedKeyForNumber:(NSString*)key fromObjectByKey:(NSString*)object eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
303 {
304     //Add error checking...
305     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
306     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
307
308     NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('%s'), from:obj { form:'prop', want:type('prop'), seld:type('%s'), from:'null'() } }", [key UTF8String], [object UTF8String]];
309     const char *sendString = [nssendString UTF8String];
310     long result = 0;
311
312     AppleEvent sendEvent, replyEvent;
313
314     DescType resultType;
315     Size resultSize, charResultSize;
316
317     AEBuildError buildError;
318     OSStatus err;
319     OSErr err2, err3;
320     /*
321         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
322             //NSLog(@"Error getting PID of application! Exiting.");
323             return nil;
324         }
325         */
326     // //NSLog(@"_sendString: %s", sendString);
327
328     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
329
330     //[self printCarbonDesc:&sendEvent];
331
332     if (err) {
333         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]);
334     }
335
336     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
337
338     //[self printCarbonDesc:&replyEvent];
339
340     if (err) {
341         //NSLog(@"Send Error: %i",err);
342     } else {
343         err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
344
345         if (err2) {
346             //NSLog(@"Error After AESizeOfParam: %i", err2);
347         } else {
348             err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, &result, resultSize, &charResultSize);
349
350             if (err3) {
351                 //NSLog(@"Error After AEGetParamPtr: %i", err3);
352             }
353         }
354     }
355
356     AEDisposeDesc(&sendEvent);
357     AEDisposeDesc(&replyEvent);
358
359     return result;
360 }
361
362 - (NSString *)sendAEWithRequestedArray:(NSArray *)array eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
363 {
364     NSString *buildString = [NSString stringWithFormat:@"{ form:'prop', want:type('prop'), seld:type('%s'), from:'null'() }", [[array objectAtIndex:0] UTF8String]];
365     const char *sendString;
366     int i;
367     NSString  *_finalString = nil;
368
369     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
370     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
371
372     AppleEvent sendEvent, replyEvent;
373
374     DescType resultType;
375     Size resultSize, charResultSize;
376
377     AEBuildError buildError;
378     OSStatus err;
379     OSErr err2, err3;
380
381     for (i = 1; i < [array count]; i++) {
382         NSString *from = [NSString stringWithFormat:@"{ form:'prop', want:type('prop'), seld:type('%s'), from:obj %@ }",
383                   [[array objectAtIndex:i] UTF8String], buildString];
384         buildString = from;
385     }
386     buildString = [@"'----':obj " stringByAppendingString:buildString];
387     sendString = [buildString UTF8String];
388     /*
389         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
390             //NSLog(@"Error getting PID of application! Exiting.");
391             return nil;
392         }
393         */
394     //NSLog(@"_sendString: %s", sendString);
395
396     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
397
398     //[self printCarbonDesc:&sendEvent];
399
400     if (err) {
401         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[buildString substringToIndex:buildError.fErrorPos]);
402     }
403
404     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
405
406     //[self printCarbonDesc:&replyEvent];
407
408     if (err) {
409         //NSLog(@"Send Error: %i",err);
410     } else {
411         unichar *result = 0;
412
413         err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
414         result=malloc(resultSize);
415
416         if (err2) {
417             //NSLog(@"Error After AESizeOfParam: %i", err2);
418         } else {
419             err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, result, resultSize, &charResultSize);
420             if (err3) {
421                 //NSLog(@"Error After AEGetParamPtr: %i", err3);
422             } else {
423                 _finalString = [NSString stringWithCharacters:result length:charResultSize/sizeof(unichar)];
424             }
425         }
426         free(result);
427     }
428     return _finalString;
429 }
430
431 - (void)sendAEWithEventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
432 {
433     //Add error checking...
434     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
435     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
436     AEDesc dest;
437     AppleEvent event, reply;
438
439     //AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, kAnyTransactionID, &event, nil, "");
440     AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest);
441     AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event);
442 //[self printCarbonDesc:&event];
443     AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, idleUPP, nil);
444 //[self printCarbonDesc:&reply];
445     AEDisposeDesc(&dest);
446     AEDisposeDesc(&event);
447     AEDisposeDesc(&reply);
448 }
449
450 - (void)printCarbonDesc:(AEDesc*)desc {
451     Handle xx;
452     AEPrintDescToHandle(desc,&xx);
453     NSLog(@"Handle: %s", *xx);
454     DisposeHandle(xx);
455 }
456
457
458 - (AEArrayDataPointer)sendAEWithRequestedKeyForArray:(NSString*)key eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
459 {
460     //Add error checking...
461     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
462     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
463
464     NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'indx', want:'%s', seld:abso($616C6C20$), from:'null'() }", [key UTF8String]];
465     const char *sendString = [nssendString UTF8String];
466     AEArrayDataPointer result = nil;
467
468     AppleEvent sendEvent, replyEvent;
469
470
471     AEBuildError buildError;
472     OSStatus err;
473
474     //NSLog(@"_sendString: %s", sendString);
475
476     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
477
478     //[self printCarbonDesc:&sendEvent];
479
480     if (err) {
481         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]);
482     }
483
484     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
485
486     //[self printCarbonDesc:&replyEvent];
487
488     if (err) {
489         //NSLog(@"Send Error: %i",err);
490     } else {
491            SInt32 count, resultCount;
492
493            AECountItems(&replyEvent,&count);
494            result=malloc(sizeof(AEDesc)*count);
495            AEGetArray(&replyEvent, kAEDescArray, result, sizeof(AEDesc)*count, NULL, NULL, &resultCount);
496
497         free(result);
498     }
499
500     AEDisposeDesc(&sendEvent);
501     AEDisposeDesc(&replyEvent);
502
503     return result;
504 }
505
506 - (long)sendAEWithSendStringForNumber:(NSString*)string eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
507 {
508     //Add error checking...
509     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
510     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
511
512     const char *sendString = [string UTF8String];
513     SInt32 result = 0;
514
515     AppleEvent sendEvent, replyEvent;
516
517     DescType resultType;
518     Size resultSize, charResultSize;
519
520     AEBuildError buildError;
521     OSStatus err;
522     OSErr err2, err3;
523     /*
524         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
525             //NSLog(@"Error getting PID of application! Exiting.");
526             return nil;
527         }
528         */
529     //NSLog(@"_sendString: %s", sendString);
530
531     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
532
533     //[self printCarbonDesc:&sendEvent];
534
535     if (err) {
536         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[string substringToIndex:buildError.fErrorPos]);
537     }
538
539     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
540
541     //[self printCarbonDesc:&replyEvent];
542
543     if (err) {
544         //NSLog(@"Send Error: %i",err);
545     } else {
546         err2 = AESizeOfParam(&replyEvent, keyDirectObject, &resultType, &resultSize);
547
548         if (err2) {
549             //NSLog(@"Error After AESizeOfParam: %i", err2);
550         } else {
551             err3 = AEGetParamPtr(&replyEvent, keyDirectObject, resultType, NULL, &result, resultSize, &charResultSize);
552
553             if (err3) {
554                 //NSLog(@"Error After AEGetParamPtr: %i", err3);
555             }
556         }
557     }
558
559
560 AEDisposeDesc(&sendEvent);
561 AEDisposeDesc(&replyEvent);
562 //NSLog(@"waffles say %d",result);
563 return result;
564 }
565
566 - (AEArrayDataPointer)sendAEWithSendStringForArray:(NSString*)string eventClass:(NSString*)eventClass eventID:(NSString*)eventID appPSN:(ProcessSerialNumber)psn
567 {
568     //Add error checking...
569     AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]);
570     AEEventID    eID    = *((unsigned long*)[eventID UTF8String]);
571
572     const char *sendString = [string UTF8String];
573     AEArrayDataPointer result = NULL;
574
575     AppleEvent sendEvent, replyEvent;
576
577     AEBuildError buildError;
578     OSStatus err;
579     /*
580         if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) {
581             //NSLog(@"Error getting PID of application! Exiting.");
582             return nil;
583         }
584         */
585     //NSLog(@"_sendString: %s", sendString);
586
587     err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString);
588
589     //[self printCarbonDesc:&sendEvent];
590
591     if (err) {
592         //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[string substringToIndex:buildError.fErrorPos]);
593     }
594
595     err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL);
596
597     //[self printCarbonDesc:&replyEvent];
598
599     if (err) {
600         //NSLog(@"Send Error: %i",err);
601     } else {
602            SInt32 count, resultCount;
603
604            AECountItems(&replyEvent,&count);
605            result=malloc(sizeof(AEDesc)*count);
606            AEGetArray(&replyEvent, kAEDescArray, result, sizeof(AEDesc)*count, NULL, NULL, &resultCount);
607
608         free(result);
609     }
610
611     AEDisposeDesc(&sendEvent);
612     AEDisposeDesc(&replyEvent);
613
614     return result;
615 }
616 @end