Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know that sounds like a weird idea, but I kinda want to experiment with this.

Over the past few months, I've kinda turned Ubuntu into my own little Frankenstein's monster, but whatever you tell me should still work. Preferably for Oneiric Ocelot.

share|improve this question

1 Answer 1

Hm, quite a hacky solution, but it works! First of all install the following things:

sudo apt-get install xmacro expect mpg321

xmacro is the program that will detect your mouse clicks. expect is the program that will listen to the output of xmacro for your mouse clicks so as to execute mpg321, which is a command line player!

So, run this script from inside a terminal:

#!/usr/bin/expect -f
spawn xmacrorec2

while { 1 } {
   expect "ButtonRelease 1"
   system mpg321 /home/alex/Music/notification/notification.mp3&
}

When you execute the above script (I repeat, through a terminal) you will be asked for an input key. Give an unusual key (e.g. F7), this will be the key that, no matter when you press it, it will stop this process from going on.

So, just, inside the above script, set mpg321 to a valid mp3 file of yours and test it :)

It works just fine under Ubuntu 12.04 but I have used all of these 3 tools under Oneiric without a problem!

xmacrorec2 may take as argument the expected key (-k argument) as a kei code. This helps you a lot if you want to put the above script to your startup applications, because it will not ask for an input key each time. In order to find the appropriate key code that you want to use, you have to install the tiny program xbindkeys:

sudo apt-get install xbindkeys

Then do:

touch ~/.xbindkeysrc
xbindkeys -k

After the last command, a small window will appear, without doing anything to it, give it a keyboard input, let's say F7. You will see something like this:

You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"(Scheme function)"
m:0x0 + c:73
F7

Notice the line:

    m:0x0 + c:73

The code 73 is the one expected by xmacrorec2. So, you can add to the above script a -k argument, like this: spawn xmacrorec2 -k 73 and it will automatically start. After you have finished editing the script, save it to a stable directory (I mean a directory you will not delete/move to the close future), like ~/Documents and give it executable permissions (right click on it->Properties->Permissions->Allow executing file as program, or, through the terminal, chmod +x script_name.sh). Then, simply add your script to your Startup Applications. Of course, whenever you want this sound to stop, you will have to give the corresponding keyboard input, like F7.

PS: If you don't want to install an extra command line mp3 player (like mpg321), then you may use the pre-installed player canberra-gtk-play, which is used as

canberra-gtk-play -f music.wav

The disadvantage of it is that it can only play certain ogg and wav files.

share|improve this answer
    
I'll try your command. Also, what means the -f in the beginning and the spawn command? –  Lucio Aug 19 '12 at 0:38
    
And don't you know something else that mpg321 to don't install an external program? –  Lucio Aug 19 '12 at 0:42
    
The manpage (man expect) guided me so as what to be my 1st line of the script. Another pre-installed command line player is canberra-gtk-play and can be called as canberra-gtk-play -f file.ogg. The con of this program is that it can only play certain ogg and wav files only. –  hakermania Aug 19 '12 at 8:37
    
Right now I can't prove your method, because of a GPG error when updating. –  Lucio Aug 19 '12 at 21:58
    
ok, take your time. –  hakermania Aug 19 '12 at 22:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.