Last active
August 29, 2015 14:01
-
-
Save stursby/0084fd53718c2b96d202 to your computer and use it in GitHub Desktop.
Cocoa NSPasteboard polling
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
@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