X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/d0e2a23f6909335baea90af08491a5160026757b..4bc5f9c0dd0d2ad6414367d8eb551676969da835:/ITAppleEventCenter.m?ds=inline diff --git a/ITAppleEventCenter.m b/ITAppleEventCenter.m index 5f485e0..bceb1ab 100755 --- a/ITAppleEventCenter.m +++ b/ITAppleEventCenter.m @@ -1,5 +1,5 @@ #import "ITAppleEventCenter.h" - +//oh, wait, i forgot i had this open. static Boolean MyAEIdleCallback ( EventRecord * theEvent, SInt32 * sleepTime, @@ -24,10 +24,9 @@ static ITAppleEventCenter *_sharedAECenter = nil; - (id)init { - if (self = [super init]) - { - idleUPP = NewAEIdleUPP(MyAEIdleCallback); - } + if (self = [super init]) { + idleUPP = NewAEIdleUPP(MyAEIdleCallback); + } return self; } @@ -41,7 +40,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; //Add error checking... AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]); AEEventID eID = *((unsigned long*)[eventID UTF8String]); - + int pid; NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('%s'), from:'null'() }", [key UTF8String]]; const char *sendString = [nssendString UTF8String]; NSString *_finalString = nil; @@ -53,17 +52,17 @@ static ITAppleEventCenter *_sharedAECenter = nil; AEBuildError buildError; OSStatus err; - OSErr err2, err3; - /* + OSErr berr, err2, err3; + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; } - */ + //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); - + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); +//joe add the ITFDEBUG stuff back? //[self printCarbonDesc:&sendEvent]; if (err) { @@ -96,8 +95,8 @@ static ITAppleEventCenter *_sharedAECenter = nil; free(result); } - AEDisposeDesc(&sendEvent); - AEDisposeDesc(&replyEvent); + if (!berr) AEDisposeDesc(&sendEvent); + if (!err) AEDisposeDesc(&replyEvent); return _finalString; } @@ -107,6 +106,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; //Add error checking... AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]); AEEventID eID = *((unsigned long*)[eventID UTF8String]); + int pid; const char *sendString = [nssendString UTF8String]; NSString *_finalString = nil; @@ -117,27 +117,27 @@ static ITAppleEventCenter *_sharedAECenter = nil; Size resultSize, charResultSize; AEBuildError buildError; - OSStatus err; + OSStatus berr,err; OSErr err2, err3; - /* + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; } - */ + //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); - - //[self printCarbonDesc:&sendEvent]; + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); + NSLog(@"sending..."); + if (!berr) [self printCarbonDesc:&sendEvent]; - if (err) { + if (berr) { //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]); } err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL); - - //[self printCarbonDesc:&replyEvent]; + NSLog(@"replying..."); + if (!err) [self printCarbonDesc:&replyEvent]; if (err) { //NSLog(@"Send Error: %i",err); @@ -161,8 +161,8 @@ static ITAppleEventCenter *_sharedAECenter = nil; free(result); } - AEDisposeDesc(&sendEvent); - AEDisposeDesc(&replyEvent); + if (!berr) AEDisposeDesc(&sendEvent); + if (!err) AEDisposeDesc(&replyEvent); return _finalString; } @@ -172,6 +172,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; //Add error checking... AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]); AEEventID eID = *((unsigned long*)[eventID UTF8String]); + int pid; NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'prop', want:type('prop'), seld:type('%s'), from:'null'() }", [key UTF8String]]; const char *sendString = [nssendString UTF8String]; @@ -184,16 +185,16 @@ static ITAppleEventCenter *_sharedAECenter = nil; AEBuildError buildError; OSStatus err; - OSErr err2, err3; - /* + OSErr berr, err2, err3; + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; } - */ + //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); //[self printCarbonDesc:&sendEvent]; @@ -221,8 +222,8 @@ static ITAppleEventCenter *_sharedAECenter = nil; } } - AEDisposeDesc(&sendEvent); - AEDisposeDesc(&replyEvent); + if (!berr) AEDisposeDesc(&sendEvent); + if (!err) AEDisposeDesc(&replyEvent); return result; } @@ -232,6 +233,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; //Add error checking... AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]); AEEventID eID = *((unsigned long*)[eventID UTF8String]); + int pid; 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]]; const char *sendString = [nssendString UTF8String]; @@ -243,17 +245,17 @@ static ITAppleEventCenter *_sharedAECenter = nil; Size resultSize, charResultSize; AEBuildError buildError; - OSStatus err; + OSStatus berr,err; OSErr err2, err3; - /* + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; - }*/ + } //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); //[self printCarbonDesc:&sendEvent]; @@ -287,8 +289,8 @@ static ITAppleEventCenter *_sharedAECenter = nil; free(result); } - AEDisposeDesc(&sendEvent); - AEDisposeDesc(&replyEvent); + if (!berr) AEDisposeDesc(&sendEvent); + if (!err) AEDisposeDesc(&replyEvent); return _finalString; } @@ -304,22 +306,23 @@ static ITAppleEventCenter *_sharedAECenter = nil; long result = 0; AppleEvent sendEvent, replyEvent; + int pid; DescType resultType; Size resultSize, charResultSize; AEBuildError buildError; - OSStatus err; + OSStatus berr, err; OSErr err2, err3; - /* + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; } - */ + // //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); //[self printCarbonDesc:&sendEvent]; @@ -347,8 +350,8 @@ static ITAppleEventCenter *_sharedAECenter = nil; } } - AEDisposeDesc(&sendEvent); - AEDisposeDesc(&replyEvent); + if (!berr) AEDisposeDesc(&sendEvent); + if (!err) AEDisposeDesc(&replyEvent); return result; } @@ -359,6 +362,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; const char *sendString; int i; NSString *_finalString = nil; + int pid; AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]); AEEventID eID = *((unsigned long*)[eventID UTF8String]); @@ -369,7 +373,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; Size resultSize, charResultSize; AEBuildError buildError; - OSStatus err; + OSStatus berr, err; OSErr err2, err3; for (i = 1; i < [array count]; i++) { @@ -379,15 +383,15 @@ static ITAppleEventCenter *_sharedAECenter = nil; } buildString = [@"'----':obj " stringByAppendingString:buildString]; sendString = [buildString UTF8String]; - /* + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; } - */ + //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); //[self printCarbonDesc:&sendEvent]; @@ -419,6 +423,8 @@ static ITAppleEventCenter *_sharedAECenter = nil; } free(result); } + if (!berr) AEDisposeDesc(&sendEvent); + if (!err) AEDisposeDesc(&replyEvent); return _finalString; } @@ -428,17 +434,23 @@ static ITAppleEventCenter *_sharedAECenter = nil; AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]); AEEventID eID = *((unsigned long*)[eventID UTF8String]); AEDesc dest; - AppleEvent event, reply; + int pid; + AppleEvent event, reply; + OSStatus cerr,cerr2,err; //AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, kAnyTransactionID, &event, nil, ""); - AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest); - AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event); + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { + //NSLog(@"Error getting PID of application! Exiting."); + return nil; + } + cerr = AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest); + cerr2 = AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event); //[self printCarbonDesc:&event]; - AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, idleUPP, nil); + err = AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, idleUPP, nil); //[self printCarbonDesc:&reply]; - AEDisposeDesc(&dest); - AEDisposeDesc(&event); - AEDisposeDesc(&reply); + if (!cerr2) AEDisposeDesc(&dest); + if (!cerr) AEDisposeDesc(&event); + if (!err) AEDisposeDesc(&reply); } - (void)printCarbonDesc:(AEDesc*)desc { @@ -458,6 +470,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; NSString *nssendString = [NSString stringWithFormat:@"'----':obj { form:'indx', want:'%s', seld:abso($616C6C20$), from:'null'() }", [key UTF8String]]; const char *sendString = [nssendString UTF8String]; AEArrayDataPointer result = nil; + int pid; AppleEvent sendEvent, replyEvent; @@ -466,7 +479,10 @@ static ITAppleEventCenter *_sharedAECenter = nil; OSStatus err; //NSLog(@"_sendString: %s", sendString); - +if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { + //NSLog(@"Error getting PID of application! Exiting."); + return nil; + } err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); //[self printCarbonDesc:&sendEvent]; @@ -475,6 +491,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; //NSLog(@"%d:%d at \"%@\"",(int)buildError.fError,buildError.fErrorPos,[nssendString substringToIndex:buildError.fErrorPos]); } + err = AESend(&sendEvent, &replyEvent, kAEWaitReply, kAENormalPriority, kNoTimeOut, idleUPP, NULL); //[self printCarbonDesc:&replyEvent]; @@ -505,6 +522,7 @@ static ITAppleEventCenter *_sharedAECenter = nil; const char *sendString = [string UTF8String]; SInt32 result = 0; + int pid; AppleEvent sendEvent, replyEvent; @@ -512,17 +530,17 @@ static ITAppleEventCenter *_sharedAECenter = nil; Size resultSize, charResultSize; AEBuildError buildError; - OSStatus err; + OSStatus berr, err; OSErr err2, err3; - /* + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; } - */ + //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); //[self printCarbonDesc:&sendEvent]; @@ -551,8 +569,8 @@ static ITAppleEventCenter *_sharedAECenter = nil; } -AEDisposeDesc(&sendEvent); -AEDisposeDesc(&replyEvent); +if (!berr) AEDisposeDesc(&sendEvent); +if (!err) AEDisposeDesc(&replyEvent); //NSLog(@"waffles say %d",result); return result; } @@ -562,6 +580,7 @@ return result; //Add error checking... AEEventClass eClass = *((unsigned long*)[eventClass UTF8String]); AEEventID eID = *((unsigned long*)[eventID UTF8String]); + int pid; const char *sendString = [string UTF8String]; AEArrayDataPointer result = NULL; @@ -569,16 +588,16 @@ return result; AppleEvent sendEvent, replyEvent; AEBuildError buildError; - OSStatus err; - /* + OSStatus berr, err; + if ((GetProcessPID(&psn, &pid) == noErr) && (pid == 0)) { //NSLog(@"Error getting PID of application! Exiting."); return nil; } - */ + //NSLog(@"_sendString: %s", sendString); - err = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); + berr = AEBuildAppleEvent(eClass, eID, typeProcessSerialNumber,(ProcessSerialNumber*)&psn, sizeof(ProcessSerialNumber), kAutoGenerateReturnID, 0, &sendEvent, &buildError, sendString); //[self printCarbonDesc:&sendEvent]; @@ -602,8 +621,8 @@ return result; free(result); } - AEDisposeDesc(&sendEvent); - AEDisposeDesc(&replyEvent); + if (!berr) AEDisposeDesc(&sendEvent); + if (!err) AEDisposeDesc(&replyEvent); return result; }