-
-
Save anonymous/fd223fd6156e7e9d317d to your computer and use it in GitHub Desktop.
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
#import <AppKit/AppKit.h> | |
#import <objc/runtime.h> | |
@interface NSPasteboard (PrivatableFindPasteboard) | |
+ (NSPasteboard *)pasteboardInterceptedPasteboardWithName:(NSString *)name; | |
@end | |
@implementation NSPasteboard (PrivatableFindPasteboard) | |
+ (NSPasteboard *)pasteboardInterceptedPasteboardWithName:(NSString *)name | |
{ | |
static NSPasteboard *privatableFindPasteboard = nil; | |
if(![name isEqualToString:NSFindPboard]) | |
return [self pasteboardInterceptedPasteboardWithName:name]; | |
if(privatableFindPasteboard == nil) | |
privatableFindPasteboard = [self pasteboardWithUniqueName]; | |
return privatableFindPasteboard; | |
} | |
@end | |
@implementation PrivatableFindClip | |
/** | |
* A special method called by SIMBL once the application has started and all classes are initialized. | |
*/ | |
+ (void)load | |
{ | |
PrivatableFindClip *plugin = [PrivatableFindClip sharedInstance]; | |
// ... do whatever | |
Class targetClass = object_getClass((id)[NSPasteboard class]); | |
Method originalMethod = class_getInstanceMethod(targetClass, @selector(pasteboardWithName:)); | |
Method newMethod = class_getInstanceMethod(targetClass, @selector(pasteboardInterceptedPasteboardWithName:)); | |
method_exchangeImplementations(originalMethod, newMethod); | |
} | |
/** | |
* @return the single static instance of the plugin object | |
*/ | |
+ (PrivatableFindClip *)sharedInstance | |
{ | |
static PrivatableFindClip *plugin = nil; | |
if (plugin == nil) | |
plugin = [[PrivatableFindClip alloc] init]; | |
return plugin; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment