Getting cmus to cooperate with conky

Screenshot of My Current Desktop

cmus is a small, fast and powerful console music player for Linux and *BSD. If you also happen to use conky, the light-weight system monitor, grabbing data from cmus and rendering it in conky is a piece of cake!

cmus comes with an application called cmus-remote that allows you to control the music player from a remote location. We’re now gonna use this app to grab the metadata and make it accessible to conky.

Since conky doesn’t have a plugin for accessing cmus directly, we need to write a simple shell script:

if [ ! -x /usr/bin/cmus-remote ];
echo "cmus is not installed."

ARTIST=$( cmus-remote -Q 2>/dev/null | grep artist | cut -d " " -f 3- )
TITLE=$( cmus-remote -Q 2>/dev/null | grep title | cut -d " " -f 3- )

if [ -z "$ARTIST" ];
echo "Nothing"
echo "$ARTIST - $TITLE"

If you have a song currently being played in cmus, you can run the script shown above in your favorite terminal, and something like “Scar Symmetry – Trapezoid” will be returned.

To get the information displayed in your conky bar, you can add the following somewhere in your .conkyrc:

${execi 2 /path/to/script}

To see an example of how a rendered bar looks like, check out the screenshot of my current desktop. I’m using the i3 window manager, and the output from conky is rendered using a combination of i3-wsbar and dzen2.

My .conkyrc is available here, and you can download the cmus-conky-script here.

Shares 0