문제

I created a service in order to show an item in the Finder's context menu.

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.

How can I remove my NSService item from the finder's context menu?

도움이 되었습니까?

해결책

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 a nil argument.

So, do what you did in applicationDidFinishLaunching:, except pass nil instead of self. (I don't know whether you'll need to do the NSUpdateDynamicServices step.)

다른 팁

If you, for example, have an uninstaller application, you can remove your menu item from Services menu in such way:

  1. Remove the application, that provides the service (the one, in which you called [NSApp setServicesProvider:self])
  2. Call 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. There could be another copy of the application elsewhere, and the clever system found it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top