Search with OS X Spotlight from emacs

I wrote previously about an idea to use the spotlight search tool in Mac OS X from within emacs. At the time, I put together some pretty crude code to do this, but I have now improved it into a package that I am quite pleased with.

The package is spotlight and is available now to install through MELPA.

The package gives you a powerful way to call spotlight from emacs. You can do a live search for a string in the text of a file, filter the file list by file name and then open the selected file with a swiper search for your query text.

Here is an example of my using it. In the animation below, I use M-x spotlight to run a spotlight search for “tomatoes”. Notice how the number of matches updates as I type or delete the last couple of characters. I then use M-RET to narrow the list of matching files using the string “docs org$” which narrows the list to files with “doc” in their full name, and with names ending in “org”. Finally once I select the file I want, swiper takes me to the matches of my original “tomatoes” query.

spotlight.gif

See the README on github for more details.

The package relies on the excellent ivy and swiper libraries to do the hard work, and benefited greatly from useful comments by redditors at /r/emacs.