Skip to content

Instantly share code, notes, and snippets.

@stursby
Last active August 29, 2015 14:01
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 stursby/0084fd53718c2b96d202 to your computer and use it in GitHub Desktop.
Save stursby/0084fd53718c2b96d202 to your computer and use it in GitHub Desktop.
Cocoa NSPasteboard polling
@implementation AppDelegate {
NSInteger lastChangeCount;
NSPasteboard *pasteboard;
}
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
pasteboard = [NSPasteboard generalPasteboard];
[NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(checkPasteboard:) userInfo:nil repeats:YES];
}
- (void)checkPasteboard:(NSTimer *)timer {
NSInteger currentChangeCount = [pasteboard changeCount];
if (currentChangeCount == lastChangeCount)
return;
NSLog(@"Pasteboard changed: %@", [pasteboard types]);
lastChangeCount = currentChangeCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment