Mac Listen for event: Copy to Pasteboard

老子叫甜甜 提交于 2019-12-12 01:03:06

问题


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?


回答1:


  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!



来源:https://stackoverflow.com/questions/16574337/mac-listen-for-event-copy-to-pasteboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!