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

查看:18
本文介绍了如何自动激活 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.

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

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.

我认为自动启用服务项目是不可能的,但我已经确认某些应用可以这样做(例如来自 Cultured Code 的事物),所以我知道它可以做到.

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.

有什么想法吗?

推荐答案

在不破解任何系统 plist 的情况下让您的服务默认启用的正确方法是编辑您自己的 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天全站免登陆