---
title: mpd control by way of rofi
date: 2025-09-18T21:36:15.000Z
---

## First off, what's mpd?
[`mpd`](https://mpd.readthedocs.io/en/latest/) is a server application for
playing music, which you can connect to using a [variety of clients](https://www.musicpd.org/clients/). You can use it to have access to your music files from anywhere on your network (and beyond, of course, depending on your network setup), or to set up a local streaming server for smart speakers around your home, or use it as centralised source for playlists or scrobbling.

Generally, it allows you to decouple _what_ you do with your music from _where_ it's stored. Personally, I use it to have my music on my NAS and be able to easily play it from anywhere, using whichever client best fits the device I'm using.

So, the minimum dependencies for using this little script are that you have an `mpd` server running somewhere
and the basic [`mpc`](https://www.musicpd.org/clients/mpc/) CLI client installed (which is generally
recommended). _Technically_, you'll also need `awk` installed, but I suspect you already do; and, of
course, `rofi` (or `wofi` or whichever your preferred fork may be).

## So, why not use one of the other clients?
I actually do mostly use [`rmpc`](https://mierak.github.io/rmpc/) when listening to music, as I often
have a few favourite albums queued up, and having a playlist queue that I can jump around is
convenient. However, its library navigation is a bit clunky and I don't always want to switch away
from whatever I'm doing, just to quickly start some music or throw on an album.

So, I thought: what if I could have something like `Telescope` and `fzf` in `Vim`, but for my music - and
preferably with a nice little interface?
And also, shouldn't it be as quick and easy to play or add music to my playlist, as it is to find
files?

I'm already used to piping [lolcate](https://github.com/ngirard/lolcate-rs) into `rofi` to quickly pull up files from my NAS, so why not do something similar for `mpd`?

## Presenting: rofi-mpd-control
![the main rofi window](./main-window.png 'The main <code>rofi</code> window shown by
<code>rofi-mpd-control</code> ||')

[`rofi-mpd-control`](https://git.sr.ht/~cybolic/nix-system/tree/main/item/packages/scripts/rofi/scripts/mpd-control.sh) is basically just piping the output of `mpc` into `rofi` and a helper script to
search the music library, with some nice parsing of `mpc`'s output to make it look nice in rofi.

The parsing of output is rather basic: we ask `mpc` to output the current status information, each
part deliminated by four tab-characters (an easily parsable deliminator that's also simple to debug
and unlikely to appear naturally) and then ask `awk` for each part.

Search and adding an album or track is a separate script that's called by `rofi-mpd-control`, called
[`rofi-mpd-search`](https://git.sr.ht/~cybolic/nix-system/tree/main/item/packages/scripts/rofi/scripts/mpd-search.sh):

![rofi showing a search for an album](./add-album.png '<code>rofi</code> showing a search for an album ||')

![rofi showing a search for a track](./add-track.png '<code>rofi</code> showing a search for a track ||')

You can find the code for it in [my NixOS flake repo](https://git.sr.ht/~cybolic/nix-system/tree/main/item/packages/scripts/rofi/scripts/mpd-control.sh). In order to run it, you'll also need the following scripts:
 - [rofi-mpd-search.sh](https://git.sr.ht/~cybolic/nix-system/tree/main/item/packages/scripts/rofi/scripts/mpd-search.sh): to find and add tracks and albums.\
    Depends on: `rofi`, `mpc` and `awk`
 - `rofi-themed`: to launch rofi with the my preferred theme.\
    You can replace that with just `rofi` without breaking anything.\
    My definition is just: `rofi -theme ${`[`inputs.rofi-themes-newmanls`](https://github.com/newmanls/rofi-themes-collection)`}/themes/rounded-purple-dark.rasi -theme-str '* { bg3: #43069af2; }' "$@"`


Also worth noting is that the background cover image will be much faster to load, if you have
[rmpc](https://mierak.github.io/rmpc/)
installed, as the default mpc client is quite slow at fetching cover-art.

### Nix
If you have Nix installed or are on NixOS, you can also just run the script directly from my repo,
without having to worry about dependencies or themes - like this:
```sh
nix shell 'sourcehut:~cybolic/nix-system#rofi' --command rofi-mpd-control
```

Or if you want to try just the search script:
```sh
# to find and add an album
nix shell 'sourcehut:~cybolic/nix-system#rofi' --command rofi-mpd-search
# or, to just find a track
nix shell 'sourcehut:~cybolic/nix-system#rofi' --command rofi-mpd-search track
```

The scripts just use `mpc`, so if you already have `mpd` working, they should just work without any
configuration needed.

## How I usually use it
I launch the script from a shortcut through [xremap](https://github.com/xremap/xremap), so my most
common use-cases are:

- **Play/Pause**: \[shortcut\] `Enter` (it's nice to see what's currently paused before playing)
- **Adding an album**: \[shortcut\] `b` `Enter` (for "al **b** um")
- **Adding a track**: \[shortcut\] `c` `Enter` (for "tra **c** k")

<small>(I also have direct xremap bindings for launching <code>rofi-mpd-search</code>, as that's usually faster
than finding things through rmpc)</small>

## In closing
I invite you to take a look at the linked scripts. Not just for the nice (in my opinion) styling of
rofi, but also as a reminder of how simple it can be to build something that looks and behaves like
a real application, using nothing more than commands piped into each other. The UNIX philosophy
still looks good 50 years later 😎.

