使用新服务项目更新OSX右键单击上下文菜单 [英] Updating OSX right click context menu with new service item

查看:88
本文介绍了使用新服务项目更新OSX右键单击上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个应用程序,该应用程序通过将NSService条目添加到我的应用程序info.plist中来公开某个文件的OSX服务(如 http://www.macosxautomation.com/services/learn/),但是我发现在将应用程序安装到新计算机上后,服务不会在查找器中快速显示单击上下文菜单.

I have created an application that exposes a OSX service for certain file by adding an NSService entry into my applications info.plist (as in http://www.macosxautomation.com/services/learn/), but I find that upon installing my application on a new machine the service doesn't show up quickly in the finder right click context menu.

我知道这是因为粘贴板服务尚未重新索引/Applications文件夹并发现"新安装的服务.

I know that this is because pasteboard services hasn't re-indexed the /Applications folder and "discovered" the newly installed service.

我还知道我可以通过手动运行/System/Library/CoreServices/pbs来强制重新索引和发现.

I also know that I can force a re-index and discovery by manually running /System/Library/CoreServices/pbs.

这里的问题是,对于初次安装我的应用程序的用户来说,确保我的服务尽快显示的最佳方法是什么.

The question here is what is the best way to ensure that my service shows up as quickly as possible for users who are installing my application for the first time.

当我的应用程序启动时,我可以执行对"/System/Library/CoreServices/pbs"的系统调用-如果用户立即启动我的应用程序-但这只能部分解决问题(此外,我想知道是否有一种更好的基于Cocoa API的方法可以做到这一点.

I could execute a system call to "/System/Library/CoreServices/pbs" when my application starts up --If the user immediately starts my application--, but that only partly solves the problem (in addition I wonder if there is a better Cocoa API based way of doing this).

如果通常仅通过上下文菜单访问我的应用程序,则用户永远不会想出局并首先启动该应用程序.他们只会在上下文菜单不存在时认为它坏了.

If my application is generally only accessed via the context menu, a user will never think to go out and start the application in the first place. They will only think it is broken when the context menu isn't there.

我没有通过安装程序分发我的应用程序.我只是提供一个可以拖放到/Applications中的捆绑软件(正如我认为Apple通常建议的那样).

I am not distributing my application with an installer. I am simply providing a bundle that can be dragged and dropped into /Applications (as I believe Apple usually suggests).

以这种方式进行安装时,是否可以加快服务发现的过程,从而使用户在任何时间都没有新安装的服务?

Is there a way to expedite the process of service discovery when doing an installation in this fashion, so that there isn't any period of time where the user is without the newly installed service?

作为旁注,该问题似乎在10.8中可能不存在(或至少是显而易见的).苹果可能在最近发布的版本中使索引编制更快.

As a side note, it appears that the problem may not exist in 10.8 (or at least be as pronounced). Apple may have made this indexing happen more quickly in their most recent release.

推荐答案

我实际上已经使用了

system("killall pbs;/System/Library/CoreServices/pbs -flush");

在我的一个应用程序中,正如您所描述的,尽管很久以前,当时还存在10.5的问题.

in one of my apps, just as you describe, though it's a long time ago, when 10.5 was in question as well.

但是,您可能想尝试此功能:

You might want to try this function, however:

void NSUpdateDynamicServices(void)

根据文档,其作用与冲洗pbs一样,但是是一种更清洁的解决方案.

which according to the documentation acts just like flushing pbs, but is a cleaner solution.

此外,如果(根据您的描述)该应用仅是一项服务,请考虑使其真正只是一项服务-请参见

Also, if (according to your description), the app is nothing but a service, consider making it a really just a service - see (Installing the Service)

To build a standalone service, use the extension .service and store it in Library/Services.

这篇关于使用新服务项目更新OSX右键单击上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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