-
Notifications
You must be signed in to change notification settings - Fork 114
Spotify extension
Skillzore edited this page Sep 25, 2018
·
22 revisions
This is a simple Spotify extension that displays the currently playing/paused song with artist and title. There are also some simple controls to pause/play, got to next or previous song and to exit spotify. Exit Spotify uses wmctrl which needs to be installed, or you can just remove the exit button from the script.
If spotify isn't running, "Spotify is not running" is displayed together with a button to start Spotify.
#!/bin/bash
# if spotify is started
if [ "$(pidof spotify)" ]; then
status=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'PlaybackStatus'|egrep -A 1 "string"|cut -b 26-|cut -d '"' -f 1)
artist=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1)
title=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1)
echo "$status: $artist - $title | iconName=spotify"
echo "---"
# show play or pause button depending on current status
if [ "$status" == "Paused" -o "$status" == "Stopped" ]; then
echo "Play | iconName=media-playback-start bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause' terminal=false"
else
echo "Pause | iconName=media-playback-pause bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause' terminal=false"
fi
# next button
echo "Next | iconName=media-skip-forward bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next' terminal=false"
# previous buton
echo "Previous | iconName=media-skip-backward bash='dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous' terminal=false"
# exit spotify
echo "Exit Spotify | iconName=application-exit bash='wmctrl -xc spotify.Spotify' terminal=false"
else
echo "Spotify is not running | iconName=spotify"
echo "---"
echo "Start Spotify | iconName=spotify bash='spotify U%' terminal=false"
fi