Applescript that efficiently listens for changes to the clipboard?

Solution 1:

I ended up solving this by using Objective C bindings for Python. So not really an AppleScript answer. It's still polling based, but it's about 1000x more CPU efficient than calling out to pbpaste from the shell.

After installing the AppKit python bindings, I can fetch the current pasteboard like this:

from AppKit import NSPasteboard, NSStringPboardType
NSPasteboard.generalPasteboard().stringForType_(NSStringPboardType)

I run this in a tight loop, polling every second, and its CPU usage is quite negligible.