I stream music on Spotify as much as the next guy, but regrettably, using the app’s Linux desktop client isn’t the most wholesome experience. Don’t get me wrong; if all you need is basic music streaming, you’ll (probably) have no complaints. Sadly, the moment your needs stretch beyond that, you’ll quickly notice that Spotify’s Linux desktop app still needs some work.
For starters, as some Shopify community members have reported, the desktop app can experience weird bugs, like a non-responsive close button, misfiring desktop notifications for local music files, and rendering/theming issues on some Linux distributions. That’s perhaps because Spotify for Linux is no longer in active development. The other unfortunate thing is the lack of an official now playing desktop widget. I find the latter especially frustrating because having to open the Spotify app every time I need to know what song is playing is a major distraction.
After getting fed up with this frustration, I decided to turn Spotify into a productivity booster by creating a desktop-integrated, custom widget that gives me a quick glimpse of the currently playing song without having to open Spotify. In this tutorial, I’ll walk you through how to do the same on your Linux system.
Every good builder needs tools
If you’ve ever wondered why Linux is the best place to learn coding, it’s because of how easy it is to combine tools and use them to create unique apps. For this project, you’ll need three primary tools: Playerctl, a Python script that you can just copy and paste into your favorite terminal text editor, and Conky. Conky creates a clean now playing widget that looks like it’s part of the wallpaper; Playerctl is a controller that interprets the raw data exchanged between media players like Spotify and the Python script.
Let’s set up these tools and a folder for the project. First, use the commands below to install Playerctl.
sudo apt update -y
sudo apt install playerctl -y
If you’re on Arch or Fedora, use the commands below:
Fedora: sudo dnf install playerctl
Manjaro/Arch: sudo pacman -S playerctl
I’m illustrating on Linux Mint. If you haven’t installed Spotify and the other tools, use the package manager or Software Center to install them, and then log in using any of the provided methods. The QR code is the easiest if you have Spotify on your smartphone.
The next step is creating the project’s brain, but before that, let’s test-run Playerctl to ensure it’s communicating with Spotify and can display the currently playing song’s metadata. Start Spotify, play a song, and then execute the command below. If Playerctl is successfully communicating with Spotify, it should print the artist’s name and song title.
playerctl -p spotify metadata –format “{{ title }} by {{ artist }}”
Before moving on, use the mkdir command to create a new directory called ‘Spotify Widget Project.’ Once created, cd into the folder to start building the project’s brain.
mkdir -p ~/”Spotify Widget Project”
cd ~/”Spotify Widget Project”
Subscription with ads
No ads on any paid plan
Price
Starting at $11.99/month, or $5.99/month for students
And now for the fun part that you’ve probably been looking forward to:
It’s time to turn the raw metadata from Spotify into a program
While cd’d into the project folder, use your favorite terminal text editor to create a Python file named spotify_now_playing.py, and copy and paste the script I’ve provided below into it. I’ll illustrate using nano since it’s beginner-friendly. Also, after saving the script, use the chmod command to make the file executable.
nano spotify_now_playing.py
#!/usr/bin/env python3
import subprocess
import textwrap
import sys
def get_prop(prop):
try:
return subprocess.check_output([“playerctl”, “-p”, “spotify”, “metadata”, prop]).decode(“utf-8”).strip()
except:
return “”
def main():
try:
status = subprocess.check_output([“playerctl”, “-p”, “spotify”, “status”]).decode(“utf-8”).strip()
except:
status = “Offline”
# Conky uses the arguments: ‘title’, ‘artist’, or ‘percent’ to call this script
arg = sys.argv[1] if len(sys.argv) > 1 else “”
if status in [“Playing”, “Paused”]:
if arg == “title”:
title = get_prop(“title”)
return textwrap.fill(title, width=22)
elif arg == “artist”:
return get_prop(“artist”)
elif arg == “percent”:
try:
pos = float(subprocess.getoutput(“playerctl -p spotify position”))
length = float(get_prop(“mpris:length”)) / 1000000
return str(int((pos / length) * 100))
except:
return “0”
else:
return “Spotify Offline” if arg == “title” else “”
if __name__ == “__main__”:
print(main())
chmod +x spotify_now_playing.py
In nano, use Ctrl + O + Enter to save the script, and Ctrl + X to exit the editor.
Configuring the Conky widget for a clean desktop
Conky is hands down the best way to create and display desktop widgets that look like a natural part of the wallpaper. If you haven’t already, install Conky using your distro’s package manager.
Linux Mint/Ubuntu: sudo apt install conky-all -y
Fedora: sudo dnf install conky
Arch/Manjaro: sudo pacman -S conky
Afterward, get back into the project’s folder (if you had cd’d out) and use a terminal text editor to create a configuration file called spotify-widget.conkyrc. Finally, copy and paste the following script into it.
nano ~/”Spotify Widget Project/spotify-widget.conkyrc”
conky.config = {
alignment = ‘middle_right’,
gap_x = 40,
gap_y = 60,
own_window = true,
own_window_type = ‘desktop’,
own_window_transparent = false,
own_window_argb_visual = true,
own_window_argb_value = 100,
own_window_colour = ‘#1DB954’, — Spotify Green
own_window_hints = ‘undecorated,below,sticky,skip_taskbar,skip_pager’,
minimum_width = 280,
minimum_height = 140,
border_inner_margin = 25,
use_xft = true,
font = ‘Ubuntu:bold:size=10’,
double_buffer = true,
update_interval = 1.0,
default_bar_height = 5,
}
conky.text = [[
# 1. Song title settings
${font Ubuntu:bold:size=16}${execi 2 python3 “/home/htg/Spotify Widget Project/spotify_now_playing.py” title}${font}
# 2. Vertically offset artist settings
${voffset 5}${color #E0E0E0}by ${execi 2 python3 “/home/htg/Spotify Widget Project/spotify_now_playing.py” artist}${color}
# 3. Progress bar settings
${voffset 15}${execbar echo $(python3 “/home/htg/Spotify Widget Project/spotify_now_playing.py” percent)}
# 4. Footer settings
${voffset 10}${font DejaVu Sans:size=9}O_O Spotify Now Playing Desktop Widget${font}
]]
After saving the configuration file, use the command below to test if the connection between Playerctl, the Python brain, and the Conky desktop widget is working. If you’ve configured everything correctly, a now playing widget should appear on your desktop.
conky -c ~/”Spotify Widget Project/spotify-widget.conkyrc”
On GNOME and a few other desktop environments, clicking the desktop may cause the widget to disappear. If you experience that, edit the conkyrc file and change own_window_type=”desktop” to ‘normal.’
Step 4: Enable delayed autostart at boot up
It’s time to make the widget persistent
The final step is setting the widget to start every time your computer boots up. To do that on Linux Mint, Ubuntu, or Fedora, go to the application menu, search for Startup Applications, and open it. Use the buttons to add a new custom command entry, fill in the details, copy and paste the following command, and save/exit. The -p 30 adds a 30-second delay that allows the wallpaper to load first.
conky -p 30 -c “/home/htg/Spotify Widget Project/spotify-widget.conkyrc”
Alternatively, you could create a .desktop file that’s guaranteed to work with any distro. Use a terminal text editor to create the file, copy and paste these configuration settings, save, and exit.
nano ~/.config/autostart/spotify-widget.desktop
[Desktop Entry]
Type=Application
Exec=conky -p 30 -c “/home/htg/Spotify Widget Project/spotify-widget.conkyrc”
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Spotify Widget
Comment=Starts now playing Spotify desktop widget for Linux
Besides being a quick and fun weekend project, the now playing Spotify for Linux desktop widget you just created can add hours of productivity to your day. Think about: how much more productive are you likely to be when you don’t have to open Spotify to know the title of the currently playing song? Start ricing your Linux desktop today!

