Adding anything to i3blocks

• 2 min read

This was initially a post about adding what’s playing on Spotify to i3blocks. I had just started using i3blocks then and thought it was pretty cool how easy it was to do. I’ve since discovered the possibilities are endless. You can add pretty much anything that outputs text to the statusbar.

Below are some examples of what’s possible.

Showing and controlling music

I like seeing what’s playing without having to bring up the Spotify app every time. If I can also control playback without bring up the app, even better.

By default, i3 comes with i3bar. I’m sure I could achieve the same thing on i3bar with enough time and effort, but its just much easier to do it with i3blocks.

Info on what’s playing can be gotten using playerctl or spotify-cli-linux.

Then add the command to the i3blocks config:

[spotify]
command=spotifycli --status
color=#00FFB3
interval=2

screenshot_1

I’ve opted to create a separate script file so I can handle mouse clicks.

#!/usr/bin/env bash

# i3blocks spotify script

spotifycli --status

case $BLOCK_BUTTON in
  1) spotifycli --prev ;;  # left click, previous
  2) spotifycli --playpause ;; # middle click, play/pause
  3) spotifycli --next ;; # right click, next
esac
; i3blocks config

[spotify-playback-status]
command=spotifycli --playbackstatus
color=#00FFB3
interval=2
separator=false

[spotify]
command=~/.config/i3blocks/scripts/spotify
color=#00FFB3
interval=2

screenshot_2 screenshot_3

I also tried this on Strawberry player using playerctl and it worked just as well.

screenshot_4

Showing Wakatime stats

Using wakatime-cli:

; i3blocks config

[wakatime]
label=
command=wakatime-cli --today
color=#3daee9
interval=300

screenshot_5

🏷  linux , i3wm