---
title: spl, a CLI for Spotlight searches
date: 2014-05-02 10:09
slug: spl-cli-for-spotlight
categories:
- Code
tags:
- cli
- spotlight
---

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](https://github.com/rcmdnk/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](http://ss64.com/osx/mdfind.html)), 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](http://brettterpstra.com/contact/). The main script is quite simple, so feel free to [play with it](https://gist.github.com/ttscoff/11476891) (or fork and send pull requests).

**[Download spl v1](https://brettterpstra.com/downloads/spl1.0.zip)**

A CLI tool for Spotlight searches

[More info](https://brettterpstra.com/2014/05/02/spl-cli-for-spotlight)

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
