title: Can I receive a callback whenever an NSPasteboard is written to?
body: <p>I've read Apple's <a href="http://developer.apple.com/library/mac/documentation/cocoa/Conceptual/PasteboardGuide106/Introduction/Introduction.html" rel="noreferrer">Pasteboard Programming Guide</a>, but it doesn't answer a particular question I have.</p>
  
  <p>I'm trying to write a Cocoa application (for OS X, not iOS) that will keep track of everything that is written to the <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html#//apple_ref/occ/clm/NSPasteboard/generalPasteboard" rel="noreferrer">general pasteboard</a> (so, whenever any application copies and pastes, but not, say, drags-and-drops, which also makes use of NSPasteboard). I could (almost) accomplish this by basically polling the general pasteboard on a background thread constantly, and checking <a href="http://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html#//apple_ref/occ/instm/NSPasteboard/changeCount" rel="noreferrer">changeCount</a>. Of course, doing this would make me feel very dirty on the inside.</p>
  
  <p>My question is, is there a way to ask the Pasteboard server to notify me through some sort of callback any time a change is made to the general pasteboard? I couldn't find anything in the NSPasteboard class reference, but I'm hoping it lurks somewhere else.</p>
  
  <p>Another way I could imagine accomplishing this is if there was a way to swap out the general pasteboard implementation with a subclass of NSPasteboard that I could define myself to issue a callback. Maybe something like this is possible?</p>
  
  <p>I would greatly prefer if this were possible with public, App Store-legal APIs, but if using a private API is necessary, I'll take that too.</p>
  
  <p>Thanks!</p>