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. :|

About these ads

7 Responses to “Improving the mocp status screensaver”


  1. 1 Nugnuts 2010/04/28 at 11:56 PM

    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/'

  2. 2 mulenmar 2010/04/29 at 7:50 AM

    Omploader appears to be down, so your images aren’t showing up. Anywhere. :(

    • 3 K.Mandla 2010/04/29 at 8:06 AM

      Yes, I noticed that. Sigh. :|

      • 4 mulenmar 2010/04/29 at 8:40 AM

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

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

        • 5 K.Mandla 2010/04/29 at 8:52 AM

          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. …

  3. 6 mulenmar 2010/04/29 at 1:05 PM

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


  1. 1 binclock and a screensaver script « Motho ke motho ka botho Trackback on 2010/06/13 at 8:08 AM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Welcome!



Visit the Wiki!

Some recent desktops


May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF
 


May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games


Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers

License

This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,959,933 hits

Archives


Follow

Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: