On Sep 19, 2014, at 3:49 AM, Daryle Walker <[email protected]> wrote:
> On Sep 18, 2014, at 7:13 PM, Keary Suska <[email protected]> wrote:
>
>> On Sep 18, 2014, at 3:22 PM, Daryle Walker <[email protected]> wrote:
>>
>>> I removed the old style type (“NSStringPboardType”) and it still worked.
>>> When I changed the “public.plain-text” to “public.url” and tested with the
>>> entry field on Firefox, Safari’s “Open URL” service showed up, but my
>>> version didn’t! Same thing happened using “NSURLPboardType” as the send
>>> type. Renaming the public name of my service, so it wouldn’t match
>>> Safari’s, didn’t work. Changing the send-type to “public.url-name” didn’t
>>> work.
>>>
>>> Now we narrowed what’s wrong. I still don’t know how to fix it.
>>
>> At this point, you are probably just looking at a UTI issue. Standard UTI's
>> are documneted in the UTCoreTypes.h header. I don't know if they are
>> documented elsewhere. Simply open terminal and execute "locate
>> UTCoreTypes.h" to find the various headers.
>
> Well, I got the “public.url” and “public.url-name” UTIs from Apple
> Development’s UTI guides. But before reading this post, I’ve been thinking
> about other line of attack.
>
> I said that my “Open URL” doesn’t register, but Safari’s does. So I want to
> see Safari’s NSServices information to see what it does. To my shock, it’s
> not there! I have no idea where the “Open URL” service that triggers Safari
> is located; I couldn’t find anything useful via Spotlight or the “find” Unix
> command. I was about to give up when I remembered that the Services menu
> shows Safari’s “Add to Reading List” command, and I did see that in Safari’s
> Info.plist.
>
> When I read the NSServices entry for “Add to Reading List,” I found out that
> Safari cheats! The service only takes RTF and UTF-8 text, put there’s a
> required-context block that filters in only URL strings and http(s) strings.
> (The latter filter is enabled by an Apple-private(?) key called
> “NSLinkSchemes.”)
>
> …
>
> I did a web-search on “NSLinkSchemes,” and found a text dump of all of
> someone’s services, and the “Open URL” service was listed as being from a
> “/System/Library/CoreServices/SystemUIServer.app.” Sure enough, my copy of
> that app has the service, and lists “NSURLPboardType” and
> “NSStringPboardType” as its send-types (in that order). Maybe I should follow
> the lead of one of these services.
>
> (The “/Applications/Font Book.app” was the only other app in the dump that
> took “NSURLPboardType,” and it was for both of its two services, and the
> fourth out of five types for both services.)
>
> …
>
> Now my web-searching has found a private Pasteboard type
> “WebURLsWithTitlesPboardType” that could be what Safari used to create URL &
> Title entries.
Here’s what I got:
> <key>NSServices</key>
> <array>
> <dict>
> <key>NSMenuItem</key>
> <dict>
> <key>default</key>
> <string>Open URL</string>
> </dict>
> <key>NSMessage</key>
> <string>openURL</string>
> <key>NSPortName</key>
> <string>MyApp</string>
> <key>NSRequiredContext</key>
> <dict>
> <key>NSTextContent</key>
> <string>URL</string>
> </dict>
> <key>NSSendFileTypes</key>
> <array/>
> <key>NSSendTypes</key>
> <array>
> <string>public.url</string>
> <string>public.url-name</string>
> <string>public.rtf</string>
> <string>public.utf8-plain-text</string>
> </array>
> </dict>
> </array>
The entry field for a service’s sendable types, in the project attributes edit
section, is ambiguous whether it means NSSendFileTypes or NSSendTypes. I had to
put an empty NSSendFileTypes to ensure what I wanted. My implementation is:
> - (void)openURL:(NSPasteboard *)pboard userData:(NSString *)userData
> error:(NSString *__autoreleasing *)error {
> NSUInteger counter = 0;
>
> for (NSPasteboardItem *item in pboard.pasteboardItems) {
> NSURL * const targetURL = [NSURL URLWithString:[item
> stringForType:[item availableTypeFromArray:@[(__bridge NSString *)kUTTypeURL,
> (__bridge NSString *)kUTTypeRTF, (__bridge NSString
> *)kUTTypeUTF8PlainText]]]];
>
> ++counter;
> if (targetURL) {
> id const browser = [[NSApp delegate] createBrowser];
>
> if (browser) {
> [browser showWindow:NSApp];
> [browser loadPage:targetURL title:[item
> stringForType:@"public.url-name"] searching:nil printing:nil showPrint:NO
> showProgress:NO];
> } else if (error) {
> *error = [NSString stringWithFormat:@"A browser window could
> not be created for item #%lu (of %lu) processed by the Service.", counter,
> pboard.pasteboardItems.count];
> }
> } else if (error) {
> *error = [NSString stringWithFormat:@"A URL was not found for
> item #%lu (of %lu) processed by the Service.", counter,
> pboard.pasteboardItems.count];
> }
> }
> }
I tried out the URL field in FireFox, and it only gives out UTF-8 text. Does
anyone know how I can test actual URL and/or URL-Name data? Am I using the new
Pasteboard API correctly?
—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]