Question

How can I create a spotlight importer for an OS X app that creates a spotlight tool like the calculator spotlight tool? It's the tool where you type in an equation and the calculator app displays the result. I want to do something like that, but I've never tried to use a spotlight importer so I don't know how I'd make that work. Is it possible to do this to begin with?

I don't need specific code, just a general idea of how I'd do that. I might even be thinking wrongly with taking an importer approach, but I'm not sure.

At this point, I don't even need a full answer. Please comment even if all you have is a seemingly inconsequential idea.

Was it helpful?

Solution

I'm pretty sure this isn't possible to do with a Spotlight importer, which is the only official interface for Spotlight integration that Apple provides.

A Spotlight importer runs only when Spotlight indexes your files (e.g. when a file of your type changes), not when Spotlight actually runs your search queries, so you have no way to directly "react" on the user's input like the built-in calculator does.

It might be possible to hack into the Spotlight UI with code injection, using something like SIMBL but that would be quite difficult and fragile (could break with system updates, etc.).

OTHER TIPS

Alfred is worth a look. Its advanced calculator feature in the free version uses GCMathParser. The user pops up the interface with a hotkey, types the equation, and it displays the result immediately. Pressing enter copies the result to the clipboard and dismisses the box. Pretty slick, in my opinion.

With the Power Pack you can build your own extensions with shell scripts or AppleScripts, though most of them seem to use Growl to display the result. Here's one that sounds similar to what you're trying to accomplish: http://thefeverdog.tumblr.com/post/10308253571/currency-converter

I'm guessing you won't use Alfred because you'd like to build this yourself, but you may find the user interface inspiring nonetheless.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top