NSServices not working

后端 未结 3 1398
终归单人心
终归单人心 2021-01-12 11:25

I\'ve been trying to get NSServices working for my application recently with no success. I have set it up according to the documentation but it does not appear in the servic

相关标签:
3条回答
  • 2021-01-12 11:50

    You need to specify a list of required contexts using NSRequiredContext. This can be empty.

    See http://lists.apple.com/archives/Cocoa-dev/2009/Sep/msg00201.html

    0 讨论(0)
  • 2021-01-12 11:56

    I have just gone trough the same problem. It seems that Snow Leopard disables the third party services by default.

    You have to open the Preferences> Keyboard Select the second tab (fast something, I don't remember right now) select the Services, look for yours, and activate it.

    There is no other workaround that I am aware of.

    0 讨论(0)
  • 2021-01-12 12:02

    The fact that it shows up in system preferences is good. You are almost there. Assuming that you already have it enabled in system preferences (a good thing to check really quick, just make sure there is check next to it), the problem is most likely an issue with the send and or return types.

    OSX uses the send and return types as hints to decided when/where to display the service. For example if you have specified a return type (as you have here) and the control that you are activating the service from doesn't know what to do with the return type, then your service won't be shown.

    The services implementation guide gave me some good trouble shooting steps on how discover why my services wasn't being displayed when I recently had the same problem (see: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/Articles/properties.html)

    If your Service is recognized by pbs, but does not appear in the Services menu, you can use the NSDebugServices user default to help determine why. For example, to determine why Mail’s Services appear or do not appear in TextEdit, you can launch TextEdit with the NSDebugServices option and pass it the bundle identifier of Mail:

    /Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices com.apple.mail

    When I did this I got a nice error message for my own application:

    MyExampleService (com.blah.example) is disqualified because its send and/or return types cannot be handled by the requestor <NSTextView: 0x7fb681c0e8a0>

    I found that my service would show up if I didn't specify and return type, and the error message clearly shows that the return type was the problem in my case. I think it is probably the problem in your case as well since you have specified a return type without specifying anything inside of it.

    Either remove the return type if you don't expect anything back, or if you want text back (for example you want your service to replace text inside of an NSTextView) I would specify the return type as an NSStringPboardType as follows:

                        <key>NSReturnTypes</key>
                        <array>
                                <string>NSStringPboardType</string>
                        </array>
    

    There might be something wrong with the send types as well, although I don't think there is. You can be sure that if you use the debugging steps I suggested that you will be told why the service doesn't show up though.

    0 讨论(0)
提交回复
热议问题