talideon.com

Blackout Ireland

January 29, 2007 at 9:38AM Stupid ROX Hacks: Play in Background

Sometimes I want to play a tune in the background without having to open up a full-blown music player or media library, say, a promotional one I picked up on I Guess I’m Floating, Nialler 9, or some other music blog. After getting sick of having of having my playlist filled with junk I deleted long ago, I knocked out a short, if a little overly paranoid, shell script for doing just that. Here it is:

#!/bin/sh
#
# Play in Background
# by Keith Gaughan (http://talideon.com/)
#
# Starts a music player, killing the currently playing one if it exists.
#
# Copyright (c) Keith Gaughan, 2007.
# Freely redistributable under the BSD license.
#

# If /bin/sh isn't bash...
if [ "$UID " = " " ]; then
	UID=`id -ru`
fi

PID_FILE=/tmp/play_in_background.$UID.pid
# It's only safe to kill the process if it's us who logged the PID the
# last time.
if [ -O "$PID_FILE" ]; then
	LAST_PID=`cat $PID_FILE`
	kill $LAST_PID
fi

for PLAYER in mpg321 mpg123; do
	LOCATION=`which $PLAYER`
	if [ -x "$LOCATION" ]; then
		$LOCATION "$@" &
		break
	fi
done

# Save the PID of the player just spawned.
echo $! >$PID_FILE

To set this up in ROX, right-click on an audio file and select Customise Menu... from the file menu. A filer window should have popped up in which you can put simlinks to the script or drop the script itself into. Either way, drop it in there, give it a suitable name, and make sure it’s executable. It should now appear in your menu.

If you want it to run whenever you click on an audio file, again, right click on an audio file and select Set Run Action... from the file menu. Now drag the shell script from the filer and onto the dialogue box, and click Use Command. And now you’re set!

I give no guarantees that this’ll run on any other Unix or *nix clone besides FreeBSD, and if you use one of those other uncouth filers such as Nautilus or Konqueror, you’re on your own as far as setting it up goes... [smile]

Comments

1 On February 3, 2007 at 2:08, Topper wrote:

Ya ROX is a great game. You forgot the link: http://www.autofish.net/shrines/rox/index.html :p