如何在OS X服务菜单中自动激活项目

Lev*_*ink 3 macos cocoa objective-c

我需要在服务菜单中默认启用我创建的服务.

我为我的OS X应用程序(在Snow Leopard上运行)创建了一项服务.我已经像这样配置了Info.plist:

<key>NSServices</key>
<array>
    <dict>
        <key>NSSendTypes</key>
        <array>
            <string>NSStringPboardType</string>
        </array>
        <key>NSMessage</key>
        <string>dropService</string>
        <key>NSMenuItem</key>
        <dict>
            <key>default</key>
            <string>Drop Service</string>
        </dict>
        <key>NSPortName</key>
        <string>MyApp</string>
    </dict>
</array>
Run Code Online (Sandbox Code Playgroud)

到目前为止,我遵循以下其他步骤:http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/introduction.html,一切似乎都正常.

我跑了命令:

/System/Library/CoreServices/pbs
Run Code Online (Sandbox Code Playgroud)

现在我的服务显示在"系统偏好设置 - >键盘 - >键盘快捷键 - >服务"下.所以系统知道它.但它不会显示在服务菜单中,除非我手动激活它.

当我尝试调试服务时,我收到以下消息:

/Applications/TextEdit.app/Contents/MacOS/TextEdit -NSDebugServices com.myapp.MyApp
Drop Service (com.myapp.MyApp) is disabled in the services menu and disabled in the context menu, by the standard Services policy.
Run Code Online (Sandbox Code Playgroud)

我不知道"标准服务政策"是什么,我在Apple开发者网站上找不到任何对此错误的引用.

我认为自动启用服务项是不可能的,但我已经确认某些应用程序会这样做(比如来自文化代码的东西)所以我知道它可以完成.

有任何想法吗?

Pet*_*sey 12

默认情况下启用服务而不破坏任何系统plist的正确方法是编辑自己的plist.具体来说,NSRequiredContext在每个服务字典中添加密钥.此信息来自此邮件列表帖子(取自类似问题的答案).

至于您需要为该密钥提供的值,文档将填写您的信息.


Nic*_*ore 11

只需在Info.plist中添加一个带有空白字典的NSRequiredContext键作为其对象.这是它应该看起来的样子:

<key>NSRequiredContext</key>
<dict>
</dict>
Run Code Online (Sandbox Code Playgroud)