简体   繁体   中英

Updating OSX right click context menu with new service item

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.

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

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.

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.

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?

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.

I've actually ended up using

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

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM