Skip to content
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, go 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.

Spotify extension screenshot running Spotify extension screenshot not running

This is all done using Mopidy, and their Spotify extension. It should be included when installing Spotify (at least I can't remember installing it separately), but should you need to install it for some reason, it can be found here.

#!/bin/bash

# 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, go to next or previous song and to exit spotify. Exit Spotify uses [wmctrl](http://tripie.sweb.cz/utils/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.
# ![Spotify extension screenshot running](https://i.imgur.com/bF2NGBr.png)
# ![Spotify extension screenshot not running](https://i.imgur.com/fFhEEZs.png)
# Made by [Skillzore](https://github.com/Skillzore)

# 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

Save as ~/.config/argos/spotify.1s.sh and don't forget to make it executable!

Made by Skillzore