Today I was thinking about apps like Clippy and other clipboard managers, I thought: “For sure swift provides notification for the copy event”
WRONG! I sadly discovered that on MacOS unlike on iOS you can’t listen for
So I wanted to write a small snippet of code that provides a notification when the clipboard changes.
The only solution is “polling” but what does that mean?
You need to check
changeCount and if it’s changed send a notification, let’s see how:
Easy right? Then to get notified you can listen as always via the
NotificationCenter like shown below:
That’s it! Quick and easy!
If you just want to play check out the example project on my Github:
Live clipboard viewer. Contribute to Rawnly/Pasty development by creating an account on GitHub.
You might find interesting also: