Tuesday, January 10, 2012

ubuntu 11.10 bash beep script

Like my title sad, i've been forced by myself to write a bash script for producing some good sound from bash scripts. Why i wrote a script? The answer is in my laziness to do deeply investigation in operation system core.
So we have:

  1.  Need to produce some notification sound (possibly error and success ones), when our script reach  final steps in it execution. 
  2. Do it as simple as possible.
My not deepest googling  provides me with this links:

Only last link definitely  shed light on my problem. And I decide to write small script that will be capable to play ubuntu native *.ogg files with it's own native  library wich in turn plays this particular sounds in real time, just i belive? like ubuntu does.

So following bash snippet will help to establish my, or someone needs:

#!/bin/bash
if [[ $1 == "" ]];then
echo -e "\tbeep [|]\ncreated by "
fi
if [[ $1 == "error" ]];then
sound="/usr/share/sounds/freedesktop/stereo/suspend-error.oga"
fi
if [[ $1 == "done" ]];then
sound="/usr/share/sounds/freedesktop/stereo/complete.oga"
fi
canberra-gtk-play --file="$sound" &>/dev/null

How to install it and run:
  1. cp or simlink it with sudo to any in your $PATH environment
  2. to run it: type in terminal "beep error" or "beep done"
  3. If you hear nice sounds all is good if not, post me back and i'll try to fix it up.
Script is available for download in my ubuntu.one account.

No comments:

Post a Comment