- AECreateDesc(typeProcessSerialNumber,(ProcessSerialNumber*)&psn,sizeof(ProcessSerialNumber),&dest);
- AECreateAppleEvent(eClass,eID,&dest,kAutoGenerateReturnID,kAnyTransactionID,&event);
-[self printCarbonDesc:&event];
- AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, idleUPP, nil);
-[self printCarbonDesc:&reply];
- AEDisposeDesc(&dest);
- AEDisposeDesc(&event);
- AEDisposeDesc(&reply);
+ 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];
+ err = AESend(&event, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, idleUPP, nil);
+//[self printCarbonDesc:&reply];
+ if (!cerr2) AEDisposeDesc(&dest);
+ if (!cerr) AEDisposeDesc(&event);
+ if (!err) AEDisposeDesc(&reply);