The Haiku/BeOS Tip Server
Tips and tricks for Haiku/BeOS users

Shuffle your startup sound

Contributed by: Don Firth
This tip is valid for: Both BeOS and Haiku

If you’d like to have a different sound played automatically every time you start your machine, you’ll want to run a brief script on startup that chooses a random sound or song from a given directory, then play it using either the built-in Sounds preferences panel or by specifying the path to your favorite audio player.

This tip assumes that your sound files are stored in /boot/home/config/sounds — edit to suit if you store them elsewhere.

Add the following to /boot/home/config/boot/UserBootscript:


N=`date +%S`
N=`expr $N + 0`
I=0
for file in /boot/home/config/sounds/*; do
	I=$[$I + 1]
done

N=$[($I * $N) / 60]
for file in /boot/home/config/sounds/* ; do
	if [ $N -eq 0 ]
		then
		rm /boot/home/config/settings/Sound
		ln -s "$file" /boot/home/config/settings/ Sound
		break
	fi
	if [ $N -ne 0 ]
		then
		N=$[$N - 1]
	fi
done

Now, copy one of your sound files to /boot/home/config/settings and rename it “Sound.” If you want the sound to be played via the operating system’s built-in startup sound function, launch the Sounds preferences panel, select Startup in the main panel, and choose Other… from the picklist. Navigate to /boot/home/config/settings/Sound.

Alternatively, you can simply point SoundPlay, MediaPlayer, or any other audio player at your Sound link from ~/config/boot/UserBootscript. For example:

MediaPlayer /boot/home/config/settings/Sound & 

Make sure the audio format of the sounds you choose are supported by the player you use.

The idea and 99% of code for this script was taken from the tip Shuffle your background Images by Jason Scaroni.

Posted in Scripting

Comment on this tip

Comments may be incorporated into the original tip by site editors.

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.