Skip to content

Instantly share code, notes, and snippets.

Created April 27, 2015 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/fd223fd6156e7e9d317d to your computer and use it in GitHub Desktop.
Save anonymous/fd223fd6156e7e9d317d to your computer and use it in GitHub Desktop.
#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