I’ve been playing with wrappers for OS X’s command line Spotlight tool mdfind for a while now. I’ve gone through many permutations, including a tool that maintains “smart folders” by symlinking the results of a Spotlight search for the contents of a .query file in a folder. That one’s not ready for prime time yet, but I found another (probably handier) solution.

A Bash/zsh script called Sentaku provided exactly the interface I needed to make this work. This script is just a quick example of how it could be used, but it’s already become a handy tool for me. It simply runs a spotlight query from the command line and gives you a “graphical” menu for selecting one of the results. You then provide a command (or just hit Enter to run open on it) and it executes the result.

Queries are the same as mdfind (man page), which can use interpreted syntax (kind:text date:today) or raw kMDItem query strings.

To use the script, unzip the download and place both files into a folder in your path (probably /usr/local/bin/). Make sure they’re executable (chmod a+x spl sentaku). Then you can just run spl "kind:text date:today" and get a menu of all the text files created in the last day. Select one and hit Enter and it will ask you what command to run. Enter a command (mmdc,subl,etc.) or just hit Enter to open in your default text editor.

Like I said, this is a quick example. I’ll probably develop it further, and if you have any ideas for it, let me know. The main script is quite simple, so feel free to play with it (or fork and send pull requests).

spl v1

A CLI tool for Spotlight searches

Published 05/02/14.

Updated 05/02/14. Changelog

DonateMore info…