Spotify has a good Linux client. But it doesn’t support MPD, so it is problematic to interact with Spotify using shortcuts or create a blocklet in i3 statusbar. Here I’d like to show how it could be achieved. At end we’ll have following blocklet:
Spotify CLI
First of all let’s see how we can control Spotify from the command line. Luckily Spotify app supports MPRIS2 DBus specification, which basically means that you can send dbus messages to Spotify with actions, like play/pause, next, etc. To simplify this process here is the bash script which wraps it in handy functions: gist.github.com/streetturtle/fa6258f3ff7b17747ee3.
Let’s install it:
Test it by running sp help
.
i3 shortcuts
With sp
installed it’s pretty simple to create keyboard shortcut, I’m using following combinations:
mod
+.
- next trackmod
+,
- previousmod
+/
- play/pause
Add following snipped to your i3 config:
~/.config/i3/config
i3 blocklet
Here is also nothing special. sp
has two methods which is used in this blocklet - sp current-oneline
to get the current artist and song name and sp status
which tells if music is currently playing or not. This blocklet also supports mouse controls. Please note that you will need to install Font Awesome to have a play/pause icon.
Create spotify_blocklet file under ~/.config/i3/ with following content:
~/.config/i3/spotify_blocklet
Make it executable (chmod +x ./spotify_blocklet
) and test it by executing. Finally in .i3blocks.conf add blocklet definition: