Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 593
John Bowers Avatar asked Aug 13 '12 20:08

John Bowers


People also ask

How do I edit the context menu on a Mac?

Customize Contextual Menus with AutomatorStart Automator from your Applications folder or Launchpad. Choose Service for your document. At the right-hand panel, select "files or folders" in "Service receives selected". Then, at the left-hand panel, select Files & Folders > Rename Finder Items.

How do you add a new document to the right-click menu on a Mac?

Install New File Menu and enable it as a Finder extension. To do so, open the Settings app, go to Extensions and enable it. What is this? Right-click inside a Finder window and you will see options to create a new text file, a new RTF document, a new Pages document, etc.


1 Answers

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.
like image 186
Charlie Monroe Avatar answered Sep 18 '22 17:09

Charlie Monroe