Rendering your current Clementine track in Conky

I've been using Clementine as a replacement for Amarok for the last few months (it's fairly feature complete, and you don't have to have all of KDE loaded into memory, so it is actually fast). As I also use Conky, it's only natural to want the currently playing track to be rendered in Conky. This isn't too hard, since Clementine exposes this information via dbus. You can see code to do this below:

#!/bin/bash
TRACK=`qdbus org.mpris.clementine /TrackList \
org.freedesktop.MediaPlayer.GetCurrentTrack`
qdbus org.mpris.clementine /TrackList \
org.freedesktop.MediaPlayer.GetMetadata $TRACK \
| sort -r | egrep "^(title:|artist:)" | sed -e "s/^.*: //g" \
| sed -e ':a;N;$!ba;s/\n/ - /g' | head -c 36

I put this in a script called nowplaying, and when run, it gives me output in Track name - Artist format. I cut off the output after 36 characters because that's about the size of my Conky window, and songs with longer names will cause Conky to automatically resize its window, which I think is distracting. You can chop the last bit off if you don't want this. Also, although I generally prefer Artist - Track Name notation, I can usually tell who the artist is, so I listed the track name first in case the combination was over my 36 character limit. You can switch it back to Artist - Track name by removing the -r flag from the sort command above.

Now, to get this information into Conky, add a line to your ~/.conkyrc that looks something like this:

Now playing: ${execi 10 ~/config/bin/nowplaying}

Every 10 seconds, this will ping Clementine and ask it what is playing. If nothing is playing (or clementine is not running), this will simply render the empty string.

Gmail, Conky, and libnotify

Several years ago I discovered a fantastic system monitor named conky. Over the years I've been tweaking my .conkyrc and it has really evolved into a little command center all on it's own. However, I read my e-mail through a mutt, and thus to check it I have to open mutt and look and see if I have any new mail. This is often obnoxious, because I'll either forget to check and miss something until later, or I'll check a lot and not get any e-mail. Today it occurred to me "hey, computers are good at repetitive tasks!", so I decided to automatically check my e-mail and render the results in conky. I also have heard lots of noise about libnotify, and how wonderful it is, so I decided to use that as well. The result is a script which checks a user's Gmail (using a password stored in a keyring), updates conky, and shows a libnotify notification if necessary. It also supports querying of arbitrary Gmail labels, allowing you to display unread counts for other e-mail addresses you might possibly have mapped to your Gmail account.

You can get your own copy to play around with if you like. It's fairly well documented, but I'll answer any questions anyone has. The dependencies (at least on Ubuntu) are python-notify python-keyring and your favorite of: python-keyring-gnome or python-keyring-kwallet.

I've released it under a beerware style license, in hopes that someone, somewhere, might find it useful. Feedback is appreciated!