[英]Cocoa: how to remove item from Finder's context menu via service?
I created a service in order to show an item in the Finder's context menu. 我创建了一项服务,以便在Finder的上下文菜单中显示项目。
I have the following code in my application: 我的应用程序中包含以下代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[NSApp setServicesProvider:self];
NSUpdateDynamicServices();
}
I'd like to remove the item from the context menu using manipulations on the service itself. 我想使用服务本身的操作从上下文菜单中删除该项目。
I tried to do: 我试着做:
NSUnregisterServicesProvider([[NSBundle mainBundle] bundleIdentifier]);
But it killed all the services for few seconds, and when it revived my service was in the services list in the Finder context menu.
但是它杀死了所有服务几秒钟,并且当它恢复时,我的服务在Finder上下文菜单的服务列表中。
How can I remove my NSService item from the finder's context menu? 如何从查找器的上下文菜单中删除我的NSService项目?
The documentation says : 该文件说 :
You should not use this function to unregister the services provided by your application.
您不应使用此功能注销应用程序提供的服务。 For your application's services, you should use the
setServicesProvider:
method of NSApplication, passing anil
argument.对于应用程序的服务,应使用NSApplication的
setServicesProvider:
方法,并传递nil
参数。
So, do what you did in applicationDidFinishLaunching:
, except pass nil
instead of self
. 因此,执行您在
applicationDidFinishLaunching:
所做的操作,除了通过nil
而不是self
。 (I don't know whether you'll need to do the NSUpdateDynamicServices
step.) (我不知道您是否需要执行
NSUpdateDynamicServices
步骤。)
If you, for example, have an uninstaller application, you can remove your menu item from Services menu in such way: 例如,如果您拥有卸载程序,则可以通过以下方式从“服务”菜单中删除菜单项:
[NSApp setServicesProvider:self]
) [NSApp setServicesProvider:self]
) NSUpdateDynamicServices()
NSUpdateDynamicServices()
It rebuilds the database and checks the availability of applications, registered to provide a service. 它重建数据库并检查已注册以提供服务的应用程序的可用性。
If it doesn't help, dump the database in Terminal with /System/Library/CoreServices/pbs -dump_pboard
and look for your service and the url, that is listed for it. 如果没有帮助,请使用
/System/Library/CoreServices/pbs -dump_pboard
在Terminal中转储数据库,并查找列出的服务和URL。 There could be another copy of the application elsewhere, and the clever system found it. 可能在其他地方有该应用程序的另一个副本,而聪明的系统找到了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.