Wednesday, May 2, 2012

notify script for cmus

Recently i bought a new PC and therefore i wanted to switch to a new audio player. Usually i use amarok which is still one of the best audio player out there. But it has a big disadvantage - it uses mysql for its database, and i simple don't wanted mysql.
Though, to choose mysql for the database backend is still a good decision - if you have a really big collection.
And that's amarok's audience - users with a huge audio collection.
Well, actually i have a huge audio collection too, but since i actually just play around ~40 tracks all the time besides mostly listening to streams, i really don't wanted a audio player which depends on mysql.
While looking for a new player i found cmus. A very simple console player. It's perfect. It has all the things which i need (playlists, mp3/flac support, stream support) and also has a really tiny memory footprint.
To make the player really comfortably in kde i wrote a small script which shows me some basic information about the actual track which i'm listening too.

And that's the script:

declare -i duration=$($CMUSREMOTE -Q|$GREP "duration"|$AWK '{ print $2 }')
declare -i position=$($CMUSREMOTE -Q|$GREP "position"|$AWK '{ print $2 }')

artist=$($CMUSREMOTE -Q|$GREP "tag artist") # ${artist:10}
title=$($CMUSREMOTE -Q|$GREP "tag title") # ${title:9}

$KDIALOG --title "CMUS is playing... ($percent%)" --passivepopup "${artist:10} - ${title:9}" 3

It looks like this:

To make it even more comfortably i put some code into my .bashrc and initab.
if ! [ "$(pidof cmus)" ];
  then /usr/bin/cmus

c8:2345:respawn:/sbin/agetty -a michael 38400 tty8 linux

With that settings, cmus always get started on tty8. And with the alias p="cmus-remote -u" i just have to press "p" after login to play music (just a note: i don't use a login-manager, thats why i always login at the console and start kde/X with startx).


  1. I'm going to try it, but I'm not sure how to install Kdialog. A possible way is installing KDE stuff, maybe there is a gtk version.
    By the way it seems good.

    1. Well, kdialog usually comes from kde-base/kdialog (gentoo), which surly depend on alot of kde packages. However, there are other scripts out there too. Have a look at Initially i wrote that script because i couldn't find one for kde, whereas there are one for gnome/unity, awesome and conky... :)