Last active
April 21, 2016 12:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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