om3ganet
March 9th, 2007, 10:09 AM
Hi!
First post here, so please forgive me if this is in the wrong category, or this has already been done! (I looked, found nothing... maybe its already available somewhere?)
I've wanted to make Ubuntu play a sound whenever I connect a USB device to my computer (like in XP), but I found no such option anywhere, so I decided to write a script that would play a sound for when a USB device was connected, and another sound when disconnected.
Firstly you'll need to have sox installed (gives the console play command):
sudo apt-get install sox
And requires two files (I copied and renamed from Windows XP) named insert.wav and remove.wav in /usr/share/sounds/ (can edit script to change location, etc). Place the following in a file, give it exec access (chmod, etc):
#!/bin/sh
# USB Insert / Remove sound script
# Created by om3ganet (msn@om3ga.net)
# --------------------------------------------------
# This script could probably be cleaned up, and add checking
# of unrecognised usb sounds (and play fail noise)
# change this if you want sounds elsewhere
SNDDIR=/usr/share/sounds/;
# check frequency (default 0.25 seconds)
CHECKFREQ=0.25
# Do not edit below this line
# --------------------------------------------------
DEVCOUNT=`lsusb | wc -l | awk '{ print $1 }'`
OLDDEVCOUNT=$DEVCOUNT;
while(true) do
sleep $CHECKFREQ;
DEVCOUNT=`lsusb | wc -l | awk '{ print $1 }'`
if [ $DEVCOUNT -gt $OLDDEVCOUNT ]; then
play `echo $SNDDIR`insert.wav;
else if [ $DEVCOUNT -lt $OLDDEVCOUNT ]; then
play `echo $SNDDIR`remove.wav;
fi fi
OLDDEVCOUNT=$DEVCOUNT;
done
You should be able to add it to your startup scripts (System->Preferences->Session in Gnome) so it works once you login.
This is my first script using bash, and first useful script for Ubuntu, so If anyone has any comments, or wish to point me to an already existing alternative, feel free to. I've barely tested this, it just seems to work.
Cheers,
om3ganet
First post here, so please forgive me if this is in the wrong category, or this has already been done! (I looked, found nothing... maybe its already available somewhere?)
I've wanted to make Ubuntu play a sound whenever I connect a USB device to my computer (like in XP), but I found no such option anywhere, so I decided to write a script that would play a sound for when a USB device was connected, and another sound when disconnected.
Firstly you'll need to have sox installed (gives the console play command):
sudo apt-get install sox
And requires two files (I copied and renamed from Windows XP) named insert.wav and remove.wav in /usr/share/sounds/ (can edit script to change location, etc). Place the following in a file, give it exec access (chmod, etc):
#!/bin/sh
# USB Insert / Remove sound script
# Created by om3ganet (msn@om3ga.net)
# --------------------------------------------------
# This script could probably be cleaned up, and add checking
# of unrecognised usb sounds (and play fail noise)
# change this if you want sounds elsewhere
SNDDIR=/usr/share/sounds/;
# check frequency (default 0.25 seconds)
CHECKFREQ=0.25
# Do not edit below this line
# --------------------------------------------------
DEVCOUNT=`lsusb | wc -l | awk '{ print $1 }'`
OLDDEVCOUNT=$DEVCOUNT;
while(true) do
sleep $CHECKFREQ;
DEVCOUNT=`lsusb | wc -l | awk '{ print $1 }'`
if [ $DEVCOUNT -gt $OLDDEVCOUNT ]; then
play `echo $SNDDIR`insert.wav;
else if [ $DEVCOUNT -lt $OLDDEVCOUNT ]; then
play `echo $SNDDIR`remove.wav;
fi fi
OLDDEVCOUNT=$DEVCOUNT;
done
You should be able to add it to your startup scripts (System->Preferences->Session in Gnome) so it works once you login.
This is my first script using bash, and first useful script for Ubuntu, so If anyone has any comments, or wish to point me to an already existing alternative, feel free to. I've barely tested this, it just seems to work.
Cheers,
om3ganet