Woffles Rhythmbox Widget

From awesome
Jump to: navigation, search

Contents

Introduction

Thankfully controlling Rhythmbox remotely is a fairly tast thanks to the rhythmbox-client tool. This tutorial shows you how to make a textbot that displays "Playing: whatever" and how to control Rhythmbox using mouse actions.

Programs you will need:

  • pcregrep -- grep using the PCRE syntax.
  • rhythmbox-client -- well, duhh.

Create the widget

textbox widget_rhythmbox {
	# Next track:
	mouse {
		modkey = {}
		button = "4"
		command = "spawn"
		arg = "~/.awesome/rhythmbox-adjust.sh next"
	}
	
	# Previous track:
	mouse {
		modkey = {}
		button = "5"
		command = "spawn"
		arg = "~/.awesome/rhythmbox-adjust.sh previous"
	}
	
	# Play/pause
	mouse {
		modkey = {}
		button = "1"
		command = "spawn"
		arg = "~/.awesome/rhythmbox-adjust.sh pause"
	}	
}

Create the scripts

First we need to make a script to store the configuration in:

~/.awesome/rhythmbox-values.sh

handle() {
	if [ "$1" == "" ]
	then
		echo "  Stopped. "
	else
		echo "  Playing: $1 "
	fi
}

flags=""
#flags="--no-start"
widget="widget_rhythmbox"
speed=5

This script lets you adjust which widget is drawn, how often it's drawn (speed) and what to draw (handle()). There's also flags which lets you pass extra flags to rhythmbox-client.

By default rhythmbox-client will start an instance of Rhythmbox when called, to disable this use the --no-start flag.

Also, keep in mind that the higher you set the speed the heavier the load on your system, a value between 2-10 is probably best.

The next script does the actual widget updating:

~/.awesome/rhythmbox-update.sh

. ~/.awesome/rhythmbox-values.sh

playing=`rhythmbox-client --no-start --print-playing 2> /dev/null`

echo "0 widget_tell $widget `handle \"$playing\"`" | awesome-client

Next is the script for triggering rhythmbox-client events:

~/.awesome/rhythmbox-adjust.sh

. ~/.awesome/rhythmbox-values.sh

if [ "$1" == "next" ]
then
	`rhythmbox-client $flags --next 2> /dev/null`
fi

if [ "$1" == "previous" ]
then
	`rhythmbox-client $flags --previous 2> /dev/null`
fi

if [ "$1" == "pause" ]
then
	`rhythmbox-client $flags --play-pause 2> /dev/null`
fi

# Force awesome to update:
~/.awesome/rhythmbox-update.sh

The last script monitors rhythmbox-client for changes:

~/.awesome/rhythmbox-monitor.sh

while true
do
	if [ -S ~/.awesome_ctl.0 ]
	then
		while true
		do
			. ~/.awesome/rhythmbox-update.sh
			
			sleep $speed
		done
	else
		sleep 1
	fi
done

To make sure the scripts can be executed run:

chmod +x ~/.awesome/rhythmbox-*

Final steps

The last thing you need to do is find a way to automatically run ~/.awesome/rhythmbox-monitor.sh every time you start an X session.

The usual way is to edit your ~/.xinitrc file to include the script, this might look something line:

~/.awesome/rhythmbox-monitor.sh &
exec awesome

However, you'll probably need to figure something else out if you're using a display manager like xdm, gdm or kdm.

Finally, tell awesome to reload your configuration, the usual way is to press Control-Mod4-R.

That just about covers everything, if you have any question I'm woffle on IRC.

Personal tools