Re: Still need help with Services. Is there sample code?
Re: Still need help with Services. Is there sample code?
- Subject: Re: Still need help with Services. Is there sample code?
- From: Daryle Walker <email@hidden>
- Date: Thu, 18 Sep 2014 17:22:41 -0400
On Sep 16, 2014, at 10:17 AM, Keary Suska <email@hidden> wrote:
> On Sep 16, 2014, at 6:22 AM, Daryle Walker <email@hidden> 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:
>>
>>> <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>Prairie</string>
>>> <key>NSSendFileTypes</key>
>>> <array>
>>> <string>public.text</string>
>>> </array>
>>> <key>NSRequiredContext</key>
>>> <dict>
>>> <key>NSServiceCategory</key>
>>> <string>public.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:
> <key>NSServices</key>
> <array>
> <dict>
> <key>NSMenuItem</key>
> <dict>
> <key>default</key>
> <string>Handle string</string>
> </dict>
> <key>NSMessage</key>
> <string>handleString</string>
> <key>NSPortName</key>
> <string>MyApp</string>
> <key>NSSendFileTypes</key>
> <array/>
> <key>NSSendTypes</key>
> <array>
> <string>NSStringPboardType</string>
> <string>public.plain-text</string>
> </array>
> </dict>
> </array>
which I copied, renaming my method to match. It worked! It still worked when I renamed my method back. Every time I made a change, I made sure to call the “pbs” tool to refresh the Pasteboard cache and to check said cache, and to ensure the Service was activated in the System Preferences.
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.
—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden