获取 Mac OS X 服务中选定链接的 HTML
我正在编写一个将与我的应用程序捆绑在一起的服务。用户应该能够右键单击 Safari(或其他 Web 浏览器)中的链接并调用我的服务并让它处理该链接(而不仅仅是用户右键单击时选择的文本)。
我唯一不能做的就是获取链接指向的 URL。 服务方法为您提供了一个可供读取的NSPasteboard
,我们将其称为pboard
。
尝试获取所选 HTML 的明显做法是 [pboard stringForType:NSPasteboardTypeHTML]
,但返回 nil。所以我调用了[pboard types]
,它返回了“public.utf8-plain-text”和NSStringPboardType。所以看来这个粘贴板只支持纯文本字符串。
我尝试调用 [pboard addTypes:types Owner:self]
(其中 types 是包含 NSPasteboardTypeHTML
和 nil 的数组),但当我调用 stringForType 时没有什么区别:。
当 [pboard types]
仅返回纯字符串类型时,我可以以某种方式从粘贴板中提取 HTML 吗?当我的服务被调用时,我是否能够控制粘贴板上的内容和/或从中读取的内容?
I'm writing a Service that will be bundled with my application. The user should be able to right-click on a link in Safari (or another web browser) and call my Service and have it process the link (not just the text that gets selected when the user right-clicks).
The only thing I can't do is get the URL the link points to. The service method gives you an NSPasteboard
to read from, which we'll call pboard
.
The obvious thing to try to get the selected HTML would be [pboard stringForType:NSPasteboardTypeHTML]
, but that returned nil. So I called [pboard types]
, and it returned "public.utf8-plain-text" and NSStringPboardType. So it seems like this pasteboard only supports plain-text strings.
I tried calling [pboard addTypes:types owner:self]
(where types is an array containing NSPasteboardTypeHTML
and nil), but it made no difference when I called stringForType:
.
Can I somehow extract HTML from the pasteboard when [pboard types]
only returns plain string types? Am I able to control what gets put onto the pasteboard and/or what gets read from it when my Service gets called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论