Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmunz/7216998 to your computer and use it in GitHub Desktop.
Save markmunz/7216998 to your computer and use it in GitHub Desktop.
Avoiding the AESendMessage bug from 10.8.2 and, apparently, 10.9.0
+ (NSAppleEventDescriptor*)mm_appleEventWithEventClass:(AEEventClass)eventClass
eventID:(AEEventID)eventID
targetApplicationBundleID:(NSString*)bundleID
{
//NSAppleEventDescriptor *target = [NSAppleEventDescriptor descriptorWithDescriptorType:typeApplicationBundleID
// data:[bundleID dataUsingEncoding:NSUTF8StringEncoding]];
NSAppleEventDescriptor *target = [self mm_targetDescriptorForBundleID:bundleID];
return [NSAppleEventDescriptor appleEventWithEventClass:eventClass
eventID:eventID
targetDescriptor:target
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
}
+ (NSAppleEventDescriptor*)mm_targetDescriptorForBundleID:(NSString*)bundleID
{
NSRunningApplication* runningApplication = [[NSRunningApplication runningApplicationsWithBundleIdentifier:bundleID] lastObject];
pid_t pid = [runningApplication processIdentifier];
NSAppleEventDescriptor *target = [[[NSAppleEventDescriptor alloc] initWithDescriptorType:typeKernelProcessID bytes:&pid length:sizeof(pid)] autorelease];
return target;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment