Get HTML of selected link in a Mac OS X Service
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 ow开发者_如何转开发ner: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?
精彩评论