Show the current music credits in the XFCE Panel
Posted on Fri 02 October 2020 in linux • 2 min read
Update 2024: I updated the script to the version actually in use, with some minor improvements and some added features.
I usually listen to music while working and every once in a while I ask myself what the current track might be. I could switch to my music player or have a look in the sound control plugin of the XFCE panel, but that involves clicking or moving the focus. I was looking for a way to just display the current tracks artist und title in the panel, but there was no indicator for that.
I came up with a small script which is called periodically by the Generic Monitor plugin. The script has a dependency on playerctl which is used to get the current metadata from players which have a DBUS interface. The script will display the current tracks title and artist if something is playing and pad the output with spaces to the left. This is done to prevent the indicator in the middle of the screen to move around to much when the length of the information changes. As I do not use a monospaced font there is some difference none the less, but it could be much worse.
The script is as following, it makes it also possible to click on the panel item to pause or unpause the current player:
#!/bin/bash
player="$(playerctl -a -f '{{playerName}} {{status}}' status 2>> /dev/null | grep Playing | head -n1 | cut -d ' ' -f1)"
playpausecmd="playerctl play-pause"
if [[ "$player" ]];
then
title="$(playerctl -p "$player" metadata title)"
if playerctl -p "$player" metadata | grep -q artist;
then
artist="$(playerctl -p "$player" metadata artist)"
fi
album="$(playerctl -p "$player" metadata album 2>> /dev/null)"
fi
if [ -n "$title" ]
then
if [ -n "$artist" ]
then
text="${artist} - ${title}"
else
text="${title}"
fi
(( ${#text} > 50 )) && text="${text:0:47}..."
printf "<tool>%s\n%s\n%s</tool>" "$title" "$artist" "$album" | sed 's/&/&/'
fi
printf "<txt>%50s</txt>\n" "$text" | sed 's/&/&/'
echo "<txtclick>$playpausecmd</txtclick>"
echo "<css>.genmon_value { padding-left: 5px; padding-right: 5px}</css>"
There is some inconsistency with the playerctl metadata artist
command, as
this will display the first available artist. If the current player does not
provide one it will look at the next player. The radio streams I tested only had
the icy-title
tag set, so the script will check if the active player actually
provides the artist
value before extracting it. This works also for Chrome,
so e.g. YouTube videos will also be displayed with the uploader and the title.
For me it looks like this: