Mac听事件:复制到粘贴板 [英] Mac Listen for event: Copy to Pasteboard

查看:486
本文介绍了Mac听事件:复制到粘贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读NSPasteboard,然后想要查找....


  1. 我试图找到正确的通知方法它监听到剪贴板上的数据的复制事件。


  2. 此外,我正在尝试查找复制到剪贴板的数据的文件路径。


  3. 如果我从浏览器中的页面复制文本,我想知道如何获取URL的url地址


  4. h2_lin>解决方案


  1. 没有可用的通知。 Devara Gudda 是对的。您请求Pasteboard中的信息以检查更改(changeCount应该是一个指标)。

您应该记住系统粘贴板一个共享容器,只存储它包含的数据的信息。所有应用程序可以随时访问它以获取数据。就是这样。没有其他信息。



现在这里是你必须做一些技巧来连接贴图板数据与你需要的一些环境状态。



是的,我已经设法获取粘贴板数据的源应用程序。我正在跟踪当前活动的应用程序所有的时间我的应用程序正在运行。当粘贴板更改它的内容我可以看到什么应用程序是活动的在这个时候。现在这不是一个理想的解决方案 - 有些情况下不能被这种方法覆盖。但仍然可以在99%的情况下工作。



我不知道如何获得问题#2和#3所需的信息。但我希望你能应用这种知识,并发明一些棘手的方式:)



祝你好运!


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. 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!

这篇关于Mac听事件:复制到粘贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆