I’m trying out writing a Service associated with my app:

> @implementation PrServicesProvider
> 
> - (void)openURL:(NSPasteboard *)pboard userData:(NSString *)userData 
> error:(NSString *__autoreleasing *)error {
>     NSURL * const     targetURL = [WebView URLFromPasteboard:pboard];
>     NSString * const  targetTitle = [WebView URLTitleFromPasteboard:pboard];
> 
>     NSLog(@"Open URL: %@ with title %@.", targetURL, targetTitle);
>     if (targetURL) {
>         id const  browser = [[NSApp delegate] createBrowser];
> 
>         if (browser) {
>             [browser loadPage:targetURL title:targetTitle];
>         } else if (error) {
>             *error = @"Browser window could not be created for the Service.";
>         }
>     } else if (error) {
>         *error = @"No URL found for the Service.";
>     }
> }
> 
> @end


I added a Service entry for the Info.plist. It returns nothing and takes in 
only “public.url”. The service never showed up. I tried the “pbs” tool:

> daryle$ /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices 
> io.github.me.MyApp
> 2014-09-15 02:24:29.702 TextEdit[51303:507] NSDebugServices=io.github.me.MyApp
> Open URL (io.github.me.MyApp) is disabled in the services menu and disabled 
> in the context menu, by the standard Services policy.
> Open URL (io.github.me.MyApp) is disabled in the services menu and disabled 
> in the context menu, by the standard Services policy.


I went into the Services system-level preferences and enabled the Service. Now 
I get:

> daryle$ /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices 
> io.github.me.MyApp
> 2014-09-15 02:27:50.565 TextEdit[51341: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: 0x7fe518e20340>
>     Frame = {{0.00, 0.00}, {550.00, 389.00}}, Bounds = {{0.00, 0.00}, 
> {550.00, 389.00}}
>     Horizontally resizable: NO, Vertically resizable: YES
>     MinSize = {550.00, 389.00}, MaxSize = 
> {179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00,
>  
> 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00}
> .
> Open URL (io.github.me.MyApp) is disqualified because its send and/or return 
> types cannot be handled by the requestor <NSTextView: 0x7fe518e20340>
>     Frame = {{0.00, 0.00}, {550.00, 389.00}}, Bounds = {{0.00, 0.00}, 
> {550.00, 389.00}}
>     Horizontally resizable: NO, Vertically resizable: YES
>     MinSize = {550.00, 389.00}, MaxSize = 
> {179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00,
>  
> 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00}
> .

(I type and select things like “http://www.apple.com” in TextEdit (RTF mode), 
and the other app’s services show up.) The section of the Info.plist file is:

>       <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>NSSendFileTypes</key>
>                       <array>
>                               <string>public.url</string>
>                       </array>
>               </dict>
>       </array>

— 
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

Reply via email to