如何在OS X服务菜单中自动激活项目 [英] How do I automatically activate an item in the OS X Services Menu

查看:128
本文介绍了如何在OS X服务菜单中自动激活项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在服务菜单中默认启用一项服务。

I need to have a service I created enabled by default in the services menu.

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

I've created a service for my OS X app (running on Snow Leopard). I've configured the Info.plist like so:

<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>

到目前为止很好,我按照下面列出的其他步骤: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual /SysServices/introduction.html ,并且一切似乎都正常工作。

So far so good, I follow the other steps outlined in: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/introduction.html and everything seems to be working correctly.

我运行了命令:

/System/Library/CoreServices/pbs

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

And now my service shows up under "System Preferences -> Keyboard -> Keyboard Shortcuts -> Services". So the system knows about it. But it won't show up in the services menu unless I manually activate it.

当我尝试调试服务,我得到这个消息:

When I try to debug the service, I get this message:

/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.

我不知道标准服务政策是什么,这个错误在苹果开发者网站上。

I have no idea what the "standard Services policy" is and I can't find any reference to this error on the Apple developer site.

我认为自动启用服务项是不可能的,但我已经确认某些应用程序做它(像

I would think that automatically enabling service items is impossible but I've confirmed that certain apps do it (like Things from Cultured Code) so I know it can be done.

推荐答案

>正确的方式让您的服务被默认启用,而不破坏任何系统plists是编辑自己的plist。具体来说,在每个服务字典中添加 NSRequiredContext 键。此信息来自此邮寄列表帖子(摘自对类似问题的答案)。

The correct way to get your service to be enabled by default without hacking any system plists is to edit your own plist. Specifically, add the NSRequiredContext key in each service dictionary. This information comes from this mailing list post (taken from this answer on a similar question).

至于您需要为该键提供的值,文档将填写

As for the value you need to provide for that key, the documentation will fill you in.

这篇关于如何在OS X服务菜单中自动激活项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆