Show the current music credits in the XFCE Panel

Posted on Fri 02 October 2020 in linux • 2 min read

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:


player="$(playerctl -a -f '{{playerName}} {{status}}' status | grep Playing | head -n1 | cut -d ' ' -f1)"

if [[ "$player" ]];
    title="$(playerctl -p $player metadata title)"
    if [ "$(playerctl -p $player metadata | grep artist)" ];
        artist="$(playerctl -p $player metadata artist)"
        text="${artist} - ${title}"
    (( ${#text} > 50 )) && text="${text:0:47}..."
    echo "<tool>$(playerctl -p $player metadata album 2>> /dev/null | sed 's/&/&amp;/')</tool>"

printf "<txt>%50s </txt>\n" "$text" | sed 's/&/&amp;/'
echo "<txtclick>playerctl play-pause</txtclick>"

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:

Image showing a sample track in the panel