Basic i3blocks controls for ubuntu rhythmbox

I've switched over from Spotify to Rhythmbox today. Spotify was a bit unstable on my system, it sometimes even struggled to playback offline playlists.

I'm back to the good old "music" folder with files of long forgotten origins.  

The default ubuntu music player, rhythmbox,  seems not too bad, i don't need it to do much anyway. 

I just had to port my i3 bar script to : 

  • show the track currently playing
  • go to next track on right click
  • play/pause on left click

 

The look of the "widget", pretty basic. 

I wanted to add a play/pause icon but 

  • i didn't find a way to ask rhythmbox-client if the  music is played or paused
  • my ears are usually enough to know if anything i s playing 

I also added a little regexp to remove anything in parenthesis in the track name, to remove "(Original mix)" mentions and such. 

.config/i3/i3blocks.conf :

[music]
command=node ~/.config/i3/rhythmbox.js
interval=5

The actual node script (I suck at bash, that's why i'm using node for this)

~/.config/i3/rhythmbox.js


const {execSync}=require('child_process')

// apply click actions
switch(process.env.BLOCK_BUTTON){
case '1': execSync('rhythmbox-client --play-pause');
break;
case '3': execSync('rhythmbox-client --next');
break;
}

// get track name
const playing=(execSync('rhythmbox-client --print-playing').toString())||'';

// clean track name
const formatted=playing.replace(/\([^\)]+\)/gi,'')

// output it
console.log(formatted);