Question

I was reading NSPasteboard, then wanted to find....

  1. I am trying to find the correct Notification method that listens to the copy event of data to the clipboard.

  2. Also I am trying to find file path of the data that is copied to the clipboard. Which would be a pasteboard object.

  3. If I copy text from a page in the browser, I am trying to find out how to grab the url address of the page the text was copied from.

Any ideas?

Was it helpful?

Solution

  1. No notification available. Devara Gudda is right. You request info from the Pasteboard to check for changes (changeCount should be an indicator).

You should keep in mind that system pasteboard is a shared container, that stores only info about data it contains. All applications can access it at any time to get the data. And that's it. No additional info.

And now this is where you have to make some tricks to connect pasteboard data with some environment state you need.

Yes, I have managed to get the source-application for the pasteboard data. I am tracking currently active application all the time my app is running. And when pasteboard changes it's contents I can see what application was active at this time. Now this is not an ideal solution - there are cases that cannot be covered by this method. But still it works in 99% cases.

I don't know how you can get the info you need for questions #2 and #3. But I hope you can apply this knowledge and invent some tricky way :)

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top