Lately I’m messing around with Conky. One of the functionalities I want, is to display the current song’s title and artist somewhere in my desktop. The songs are played either through Quod Libet or on Firefox.
I found a Conky conf that uses two bash scripts so as to retrieve and display the metadata (through MPRIS). For example, for the song’s title, the script is:
#!/bin/sh
BoolS=$(qdbus org.mpris.MediaPlayer2.firefox.instance43741 /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player PlaybackStatus)
BoolC=$(qdbus org.mpris.MediaPlayer2.quodlibet /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player PlaybackStatus)
if [ "$BoolC" = 'Playing' ];
then
echo $(qdbus org.mpris.MediaPlayer2.quodlibet /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata | awk '/xesam:title:/ { print}' | sed -e "s/^xesam:title://")
elif [ "$BoolS" = 'Playing' ];
then
echo $(qdbus org.mpris.MediaPlayer2.firefox.instance43741 /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get org.mpris.MediaPlayer2.Player Metadata | awk '/xesam:title:/ { print}' | sed -e "s/^xesam:title://")
fi
The metadata for Quod Libet worked fine from the beginning.
For Firefox, I spent quite a bit of time to find out how to call it. Thanks to playerctl -l
, I saw that it was reported as firefox.instance43741
. So everything works fine… until I close the browser. When it re-opens, the instance has changed and I have to re-enter it manually into the script.
So, is there a way to automatically enter the current instance number into the script, instead of hard-coding it everytime?