Calculator-like spotlight tool
Asked Answered
I

2

8

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.

Ingenious answered 16/5, 2012 at 14:30 Comment(1)
The docs on developer.apple.com are definitely inadequate here. Lots about supporting custom file formats, nothing about live updating queries as with the calculator. Good question.Shrader
C
5

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.).

Cornu answered 19/5, 2012 at 13:4 Comment(1)
This answer makes me sad. I had a really great idea for a spotlight tool, and now it's looking like I can't do it. Oh well, I'll probably end up giving you the bounty, but I really want to believe that somebody can come up with a solution, so I'll wait until the last day to award you. Thanks for the explanation of how Spotlight Importers work, it was quite helpful in explaining basically what they are.Ingenious
K
1

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.

Kunlun answered 24/5, 2012 at 17:53 Comment(2)
This is the kind of answer that I was looking for after @Cornu answered; I was missing the inspiration that I felt when I first had the idea for this app, but seeing Alfred run has reinvigorated that inspiration. I do want to reward omz somehow for input, so I'll give him the answer acceptance and you the bounty.Ingenious
Thanks! I'm glad it complemented omz's answer.Kunlun

© 2022 - 2024 — McMap. All rights reserved.