Current Spotify song in tmux

I made a small, cute bash script to display the currently playing song on Spotify. My initial ambition was to use it with tmux, but soon I began to think it was annoying (I don’t like distractions). But the script perhaps might interest someone who’s not as easily distracted.

Make a file named for instance current-song, make it executable with chmod +x current-song, and move it to ~/.local/bin or wherever you store your scripts. Add this content,

#!/usr/bin/bash

pid=$(xprop -name spotify 2> /dev/null | grep PID | awk '{ print $3 }')

if [[ $pid ]]
then
    curr=$(wmctrl -lp | grep "$pid" | cut -c 29-)
    [[ $curr != "Spotify Premium" ]] && echo "$curr"
fi

In .tmux.conf add the path to the script in the status. For instance,

set -g status-right "#(~/.local/bin/current-song) %H:%M"

Note that you need xprop and wmctrl. If you don’t have them you must install them using your package-manager. This script should work on most nix-like systems, such as common Linux distros as well as MacOS.

Leave a Reply