Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get notified when something is added to NSPasteboard

In my application I want to get notified if something is added into the NSPasteboard. If I copy an text from any other program I want my application to know about it.

Somewhere I read it can't be done that way. I should create a timer and check the content of the NSPasteboard myself.

Is this the way to do? Or are there any kind of notifications?

like image 655
TalkingCode Avatar asked Aug 31 '10 15:08

TalkingCode


1 Answers

Yes, you essentially have to poll the pasteboard to see if its contents have changed. It's not ideal, but it's possible. Basically, you have a timer that fires once or twice a second and checks the -[NSPasteboard changeCount]. If the changeCount changes, that means the contents of the pasteboard have also changed (or there's at least a new owner).

like image 82
Dave DeLong Avatar answered Oct 13 '22 07:10

Dave DeLong