Re: Still need help with Services. Is there sample code?

2014-09-19 Thread Daryle Walker
On Sep 18, 2014, at 7:13 PM, Keary Suska cocoa-...@esoteritech.com wrote:

 On Sep 18, 2014, at 3:22 PM, Daryle Walker dary...@mac.com 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.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Re: Still need help with Services. Is there sample code?

2014-09-19 Thread Daryle Walker
On Sep 19, 2014, at 3:49 AM, Daryle Walker dary...@mac.com wrote:

 On Sep 18, 2014, at 7:13 PM, Keary Suska cocoa-...@esoteritech.com wrote:
 
 On Sep 18, 2014, at 3:22 PM, Daryle Walker dary...@mac.com 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:

   keyNSServices/key
   array
   dict
   keyNSMenuItem/key
   dict
   keydefault/key
   stringOpen URL/string
   /dict
   keyNSMessage/key
   stringopenURL/string
   keyNSPortName/key
   stringMyApp/string
   keyNSRequiredContext/key
   dict
   keyNSTextContent/key
   stringURL/string
   /dict
   keyNSSendFileTypes/key
 array/
 keyNSSendTypes/key
   array
   stringpublic.url/string
   stringpublic.url-name/string
   stringpublic.rtf/string
   stringpublic.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) 

Re: Still need help with Services. Is there sample code?

2014-09-18 Thread Daryle Walker
On Sep 16, 2014, at 10:17 AM, Keary Suska cocoa-...@esoteritech.com wrote:

 On Sep 16, 2014, at 6:22 AM, Daryle Walker dary...@mac.com wrote:
 
 Still can’t get my Service to trigger.
 
 daryle$ /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices 
 io.github.me.MyApp
 2014-09-16 08:00:58.493 TextEdit[546:507] NSDebugServices=io.github.me.MyApp
 Open URL (io.github.me.MyApp) is explicitly enabled in the services menu 
 and enabled in the context menu, in preferences.
 Open URL (io.github.me.MyApp) is explicitly enabled in the services menu 
 and enabled in the context menu, in preferences.
 Open URL (io.github.me.MyApp) is disqualified because its send and/or 
 return types cannot be handled by the requestor NSTextView: 0x7fc35345d950
   Frame = {{0.00, 0.00}, {550.00, 420.00}}, Bounds = {{0.00, 0.00}, 
 {550.00, 420.00}}
   Horizontally resizable: NO, Vertically resizable: YES
   MinSize = {550.00, 420.00}, MaxSize = 
 {179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00,
  
 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00}
 .
 
 The first two lines after the command always appear. The rest of the lines 
 happen every time I open the Services menu, no matter the context. (The 
 error messages are happening when the system checks if my Service 
 qualifies.) Web-searching got only one hit on is disqualified because its 
 send and/or return types cannot be handled by the requestor”; the page was 
 from Stack Overflow. It mentioned a post on this list from 5 years ago, 
 suggesting adding an “NSRequiredContext” entry. It didn’t help me; still 
 getting the same error. (The “MaxSize” numbers are one huge line; it wraps 
 here.)
 
 I’m stumped. I’ve been looking for Apple sample code, but since it likes 
 tacking on “service” to 80% of its stuff, I can’t find anything.
 
 Here’s the Services portion of my Info.plist, in case I’m still missing 
 something simple:
 
 keyNSServices/key
 array
 dict
 keyNSMenuItem/key
 dict
 keydefault/key
 stringOpen URL/string
 /dict
 keyNSMessage/key
 stringopenURL/string
 keyNSPortName/key
 stringPrairie/string
 keyNSSendFileTypes/key
 array
 stringpublic.text/string
 /array
 keyNSRequiredContext/key
 dict
 keyNSServiceCategory/key
 stringpublic.text/string
 /dict
 /dict
 /array
 
 I could post the source code again, but the lack of any logging from that 
 method means the process is failing before the method would be called. I did 
 at one time add an -init and -dealloc with logging just to make sure the 
 object was created and retained. I got just the init message, which means 
 that the service provider was being retained and not instant-deallocated.
 
 Oh, the Stack Overflow page was 
 http://stackoverflow.com/questions/1370616/nsservices-not-working and the 
 referenced post was 
 http://lists.apple.com/archives/Cocoa-dev/2009/Sep/msg00201.html.
 
 I am not sure how you are googling, but I found a solution as the first hit. 
 I always do full phrase searches on error messges for best results. See 
 this:http://lists.apple.com/archives/cocoa-dev/2012/Jun/msg00382.html as it 
 has the exact same problem, with solution. Use that info.plist as a sample 
 and see if you have better success.

I used “Web Searching” as a trademark-free alternate term to “Googling,” 
especially since I was using a competitor. The referenced post used:

   keyNSServices/key
   array
   dict
   keyNSMenuItem/key
   dict
   keydefault/key
   stringHandle string/string
   /dict
   keyNSMessage/key
   stringhandleString/string
   keyNSPortName/key
   stringMyApp/string
   keyNSSendFileTypes/key
   array/
   keyNSSendTypes/key
   array
   stringNSStringPboardType/string
   

Re: Still need help with Services. Is there sample code?

2014-09-18 Thread Keary Suska
On Sep 18, 2014, at 3:22 PM, Daryle Walker dary...@mac.com 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.

Keary Suska
Esoteritech, Inc.
Demystifying technology for your home or business


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Re: Still need help with Services. Is there sample code?

2014-09-16 Thread Keary Suska
On Sep 16, 2014, at 6:22 AM, Daryle Walker dary...@mac.com wrote:

 Still can’t get my Service to trigger.
 
 daryle$ /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices 
 io.github.me.MyApp
 2014-09-16 08:00:58.493 TextEdit[546:507] NSDebugServices=io.github.me.MyApp
 Open URL (io.github.me.MyApp) is explicitly enabled in the services menu and 
 enabled in the context menu, in preferences.
 Open URL (io.github.me.MyApp) is explicitly enabled in the services menu and 
 enabled in the context menu, in preferences.
 Open URL (io.github.me.MyApp) is disqualified because its send and/or return 
 types cannot be handled by the requestor NSTextView: 0x7fc35345d950
Frame = {{0.00, 0.00}, {550.00, 420.00}}, Bounds = {{0.00, 0.00}, 
 {550.00, 420.00}}
Horizontally resizable: NO, Vertically resizable: YES
MinSize = {550.00, 420.00}, MaxSize = 
 {179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00,
  
 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00}
 .
 
 The first two lines after the command always appear. The rest of the lines 
 happen every time I open the Services menu, no matter the context. (The error 
 messages are happening when the system checks if my Service qualifies.) 
 Web-searching got only one hit on is disqualified because its send and/or 
 return types cannot be handled by the requestor”; the page was from Stack 
 Overflow. It mentioned a post on this list from 5 years ago, suggesting 
 adding an “NSRequiredContext” entry. It didn’t help me; still getting the 
 same error. (The “MaxSize” numbers are one huge line; it wraps here.)
 
 I’m stumped. I’ve been looking for Apple sample code, but since it likes 
 tacking on “service” to 80% of its stuff, I can’t find anything.
 
 Here’s the Services portion of my Info.plist, in case I’m still missing 
 something simple:
 
  keyNSServices/key
  array
  dict
  keyNSMenuItem/key
  dict
  keydefault/key
  stringOpen URL/string
  /dict
  keyNSMessage/key
  stringopenURL/string
  keyNSPortName/key
  stringPrairie/string
  keyNSSendFileTypes/key
  array
  stringpublic.text/string
  /array
  keyNSRequiredContext/key
  dict
  keyNSServiceCategory/key
  stringpublic.text/string
  /dict
  /dict
  /array
 
 I could post the source code again, but the lack of any logging from that 
 method means the process is failing before the method would be called. I did 
 at one time add an -init and -dealloc with logging just to make sure the 
 object was created and retained. I got just the init message, which means 
 that the service provider was being retained and not instant-deallocated.
 
 Oh, the Stack Overflow page was 
 http://stackoverflow.com/questions/1370616/nsservices-not-working and the 
 referenced post was 
 http://lists.apple.com/archives/Cocoa-dev/2009/Sep/msg00201.html.

I am not sure how you are googling, but I found a solution as the first hit. I 
always do full phrase searches on error messges for best results. See this: 
http://lists.apple.com/archives/cocoa-dev/2012/Jun/msg00382.html as it has the 
exact same problem, with solution. Use that info.plist as a sample and see if 
you have better success.

Keary Suska
Esoteritech, Inc.
Demystifying technology for your home or business


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com