Improving the mocp status screensaver

Wednesdays are my busiest days, and unfortunately I only have time for a short note today. I hope you’ll forgive me for rehashing something I mentioned so recently, but I refined and made a few improvements to the “now playing” script for mocp, figlet and screen from a mere 10 days ago. (Additionally this might not be terrifically interesting at all, but only appeal to me … which is the best reason of all to put it here, because I’ll come looking for it later. 😉 )

Originally the “script” really only spat out the title of the song currently playing, whereas this version shows the hostname and kernel version, plus the current date and time, along with the oversize artist and title, as well as the player status and time position. Perhaps a picture is in order.

And here is the script. (Remember, no fair laughing at my programming ability. I did my best work in Commodore BASIC, so bash puts me a little out of my depth.)

#!/bin/bash
while true  
	do 
		LF="\n\n"
		STATE=`mocp -Q %state 2>/dev/null`
		ARTIST=`mocp -Q %artist 2>/dev/null`
		SONG=`mocp -Q %song 2>/dev/null`

		clear 

		echo `uname -r -s` "on" $HOSTNAME > $HOME/.scripts/header.txt
		date +"%F %T %P" >> $HOME/.scripts/header.txt
		sed  -e :a -e 's/^.\{1,133\}$/ &/;ta' -e 's/\( *\)\1/\1/' $HOME/.scripts/header.txt
		
		echo -e $LF

		case "$STATE" in
		"PLAY"
			figlet -tkc -f mini ${STATE}
			
			echo -e $LF$LF	

			figlet -tc ${ARTIST}
			figlet -tc ${SONG}

			echo -e $LF$LF	

			mocp -Q %ct\ \:\:\ %tt 2>/dev/null | figlet -tc
		;;
		*)
			figlet -tkc -f mini.flf ${STATE}
		;;
		esac

		sleep 10s  
	done

I’ll explain what I was doing, because I am sure there is a more expedient way to do these things, and knowing what I was up to might make it easier to do it better.

Basically I want three things from mocp: the title of the song, the name of the artist, and the status of the player. Those are available with the -Q query flag, and go into variables of the same name.

Because the current time can change while the script is running, the kernel and hostname are dumped into a text file, followed by the date in the format I prefer. The sed centering script is a gift from the sed one-liner collection, which is something you should have bookmarked.

I use the state variable to determine if the screensaver displays anything at all, since it looks a little odd to show “Now playing” followed by nothing. So long as the state is “PLAY”, I send the state to the screen with figlet in a small typeface, followed by a few lines of vertical spacing, with the artist and the song titles centered, followed by the current track time and the total time of the song.

That’s about it. In the opposite case, where the state isn’t “PLAY”, it only shows the state, followed by nothing. I set that as a case statement because originally I was going to include a situation where there was no song or artist, but the TITLE output from mocp. I might add that later.

Suggestions are, as always, welcomed … so long, as always, as they’re not prefixed with hysterical laughter or demeaning comments about my programming ability. Or lack thereof. 😐

7 thoughts on “Improving the mocp status screensaver

  1. Nugnuts

    Pretty spiffy 🙂

    I’m no bash expert, but I know what a fan of efficiency you are. You could avoid a teeny bit of file IO and do your sed line with a pipe ala something like:


    printf "`uname -r -s` on ${HOSTNAME}\n`date +\"%F %T %P\"`" | sed -e :a -e 's/^.\{1,133\}$/ &/;ta' -e 's/\( *\)\1/\1/'

    Reply
      1. mulenmar

        First xs.to, then omploader. This is why I just store my pictures on WordPress. 🙄

        The uploader has a “browser”, Flash-less mode btw. 😀

        Reply
        1. K.Mandla Post author

          Yes, the problem is that it would require me to use Firefox to upload a picture (or a graphical browser, anyway). omploader was text-browser friendly, and I had a script to upload photos to the site, so I could put together the whole post from my Pentium.

          It’ll probably be back in a little while. They’ve been offline in the past, but usually recover. …

          Reply
  2. mulenmar

    Personally, I’d rather use the more dependable hosting on WordPress than the less reliable service that’s easily accessed. *shrugs*

    Reply
  3. Pingback: binclock and a screensaver script « Motho ke motho ka botho

Leave a reply to mulenmar Cancel reply