Display the Current Spotify Track with bash-sensors for Cinnamon on Linux

Naomi Most
4 min readJul 30, 2024

--

From the making-linux-completely-yours dept…

I love information-rich heads-up displays. That’s why I love Cinnamon Spices applets like bash-sensors. Their versatility and simplicity make it easy to keep watch on anything from the progress of a long-running data analysis to the currently playing track on Spotify.

In this article, we'll walk through how to set up bash-sensors, a lightweight system monitoring applet, and configure it to display the current playing song from Spotify. We'll cover the installation of bash-sensors, what it can do, and the steps to integrate it with a custom script.

Introduction to bash-sensors

bash-sensors is a lightweight applet designed for Linux systems that provides real-time system monitoring directly from your desktop. It can display various system statistics such as CPU usage, memory usage, and network activity. Additionally, it can be configured to run custom scripts, allowing you to display virtually any information you want.

Dependencies:

We’ll need some packages available to get bash-sensors and make our script work. Depending on your Linux distribution, you might need to install conky, jq, and dbus:

sudo apt-get install conky jq dbus

Creating the Spotify Script

To display the current playing song from Spotify, we’ll create a custom script that fetches this information using dbus. Follow these steps:

  1. Create the Script

Create a new file named nowplaying_on_spotify.sh in your ~/bin directory:

mkdir -p ~/bin
nano ~/bin/nowplaying_on_spotify.sh

2. Add the Following Bash Code

#!/bin/bash

# Get the current playing song from Spotify using dbus
SPOTIFY_STATUS=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify \
/org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get \
string:"org.mpris.MediaPlayer2.Player" string:"Metadata")

ARTIST=$(echo "$SPOTIFY_STATUS" | grep -A 2 "xesam:artist" | tail -1 | cut -d '"' -f 2)
TITLE=$(echo "$SPOTIFY_STATUS" | grep -A 1 "xesam:title" | tail -1 | cut -d '"' -f 2)

if [[ -z "$TITLE" ]]; then
echo "Spotify is not playing."
else
echo "$ARTIST - $TITLE"
fi

3. Make the Script Executable

chmod +x ~/bin/nowplaying_on_spotify.sh

4. Check to see that the script works in the Terminal

With Spotify running, go ahead and run the script. Hopefully you see something like this:

./nowplaying_on_spotify.sh

With any luck you’ll see something like this:

nowplaying_on_spotify.sh script output when working correctly
I name all of my machines after Norse and Greek gods and goddesses.

Installing bash-sensors (GUI Method)

Your Cinnamon desktop should have a taskbar at the bottom of the screen. Right-click anywhere on that bar to see the context menu, and select “Applets.”

The Applets window has two tabs: Manage and Download. If bash-sensors is not in the Manage list yet, click on the Download tab and search for it in the search bar.

(While you’re here, you might see some other stuff to play with too. Indulge your curiosity and let the stars be your guide — some applets are better than others. My personal favorites: System Monitor, Weather, and Color Picker.)

With the applet downloaded, go back the the Manage tab, where you should see bash-sensors at or near the top of the list. Click the “+” button at the bottom of the Manage panel to add it to the panel.

Now you should see something like this on your panel:

cinnamon bash — sensors panel unconfigured
My desktop color scheme has gotten rather beige.

Excellent, the bash-sensors Cinnamon applet has been installed!

Now let’s configure it to use the script we wrote.

Configuring Bash-Sensors to Use the Spotify Script

Right-click on that “configuration required” item you see on the applet bar.

In the menu that is produced, select the “Configure” option, which will pull up a window entitled “Bash Sensors”.

In the bash-sensors configuration panel, go ahead and copy the following details into the panel. Note the refresh interval is set to 3, and we’re using two-line mode.

Feel free to style the “Now Playing” heading as per how you’d like it. You could also move the script output to Command 1 and leave out the “Now Playing” line. Turn off the “two-line” mode if you prefer it that way.

Now you should see in your panel something more fun: it’s the currently playing item on Spotify!

Your applet won’t have a red background by default; it will be neutral.

A Word of Inspiration and Also Caution

In bash-sensors literally anything you can validly execute as a bash script can be used to provide a display on the applet bar. That means you are limited only by imagination and are completely free to shoot yourself in the foot (isn’t that what we love about Linux, though).

Make sure, for example, that when you want to print out just a string like “Now Playing” that it is encased in an echo statement, which would make this statement valid on the command line.

That’s it!

Did you get this recipe working for you?

What else have you done with bash-sensors? Let me know in the comments!

Happy hacking!

--

--

Naomi Most
Naomi Most

Written by Naomi Most

Artist, Engineer, Personal Trainer, and ADHD polymath who can't stop learning new languages. Mostly Harmless Variant of Loki.

No responses yet