Skip to content

Instantly share code, notes, and snippets.

@eggman64
Forked from csssuf/bar.sh
Created July 21, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eggman64/555aef628dc6d370cb1b283346536e75 to your computer and use it in GitHub Desktop.
Save eggman64/555aef628dc6d370cb1b283346536e75 to your computer and use it in GitHub Desktop.
Adds now playing indicator from spotify or MPD to i3status
#!/bin/bash
i3status | while :
do
read line
dir=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
spotify_status=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus' | tail -n1 | cut -d'"' -f2)
spotify_artist=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk -f ${dir}/spotify_song.awk | head -n 1 | cut -d':' -f2)
spotify_song=$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk -f ${dir}/spotify_song.awk | tail -n 1 | cut -d':' -f2)
mpd_song=$(mpc current)
if [ "$spotify_status" = "Playing" ] ; then
echo -n "NP: $spotify_artist - $spotify_song | $line" || exit 1
continue
elif [ "$mpd_song" != "" ]; then
mpd_status=$(mpc status | tail -2 | head -1 | cut -d' ' -f1 | tr -d '[]')
if [ "$mpd_status" = "playing" ]; then
echo -n "NP: $mpd_song | $line" || exit 1
continue
fi
echo -n $line || exit 1
continue
fi
echo -n $line || exit 1
done
/string *"xesam:artist/{
while (1) {
getline line
if (line ~ /string "/) {
sub(/.*string "/, "artist:", line)
sub(/".*$/, "", line)
print line
break
}
}
}
/string *"xesam:title/{
while(1) {
getline line
if (line ~ /string "/) {
sub(/.*string "/, "title:", line)
sub(/".*$/, "", line)
print line
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment