Main index > Python programming > Play a sound when mailer receive new mail ?

By tonyo (User), on Sun Apr 9 11:30:37 2006: Play a sound when mailer receive new mail ?.

Hello,
I have a problem with the mailer desklet. I want to use the "beeper" but I don't understand what's happening.

Here is what I put in the file beep.sh :

Code:

#!/bin/sh
#

play question.wav


When I launch in a console ./beep.sh, the sound is played, and it is marked "playing question.wav". Unfortunately, when I receive new messages, nothing occurs. I wonder whether script is well launched by the desklet mailer... but how to check it??

Here is a part of the source of the desklet where script is launched:

Code:

    def alarm(self):
        """
        Refresh the display as needed
        """
        self.block()
        mail = self.mailer()
        self._display()
        if mail > self.mailer.last_size and mail>0:
            if self.config['program_on_new']:
                self._execute(join(self.basedir,
                                   self.config['program_on_new']))
        self.unblock()


and the function _ execute() is defined as follows:

Code:

    def _execute(self,command):
        spawnlp(P_NOWAIT, command.split()[0], *command.split())


Does somebody have an idea to make play this sound ?
thank you in advance :wink:

By syfou (Core Developer & Desklet Author), on Sun Apr 9 20:01:45 2006.

Hi Tonyo,

I would be surprised that the mailer.py -> beep.sh calling mechanism would be at stake, since I never experienced any problem after many months running it on a wide variety of systems, but who knows? Here is slightly expanded version of your beep.sh script:

Code:


#!/bin/sh

( echo 'beep!'; play question.wav ) 2>&1 | logger -sit beep



logger is part of POSIX 2, so this should work on most platforms: all it does is adding a debug output to your system logs; it should help you catch what is going wrong. Yours,

By tonyo (User), on Mon Apr 10 13:07:54 2006.

Hi !
thanks for your help Syfou.
I tried your script, but it doesn't seem to work with the mailer. In fact, its work when I launch it in a console ( ./beep.sh )

What it could help resolving my problem is to know that I'm running it under Ubuntu Breezy...
Where can I find the system logs... ?

yours,
tonyo

By syfou (Core Developer & Desklet Author), on Mon Apr 10 13:37:19 2006.

Hi,

tonyo wrote:


I tried your script, but it doesn't seem to work with the mailer.

well, this script never was corrected version of yours, but an "decorated" version that merely reports potential errors (and success) to your system logs: every time you call it, at least two new lines are added to your system's log files.

tonyo wrote:


Where can I find the system logs... ?


Here is the official Ubuntu documentation on system logs. If it's in sync with your system, it would mean that you would see the messages in /var/log/messages: As root:

Code:


grep beep /var/log/messages


Yours,

By tonyo (User), on Mon Apr 10 13:56:44 2006.

thanks a lot !

I found what's the problem. It was written in the log file "sox: Can't open input file 'question.wav': No such file or directory"

So I just changed the file path in the script :

Code:


#!/bin/sh

( echo 'beep!'; play /home/tonyo/question.wav ) 2>&1 | logger -sit beep 


...and it works !

just another little problem : it doesn't work when Amarok is playing music. How can I avoid this problem ?

tonyo

By syfou (Core Developer & Desklet Author), on Mon Apr 10 17:33:31 2006.

tonyo wrote:


It doesn't work when Amarok is playing music.

Now you know why I just emit a pc-speaker beep by default. ;-) Many, many things can cause this, from incorrect drivers settings to conflict in the oss emulation layer or alsa plugins subsystem, or even fairly high level conflicts between amarok and sox. The best place for you to enquire about this would probably be the Ubuntu Forums.

This said, my advice to you would be to simply work around this: have you tried aplay (from the alsa-utils package)? Yours,

By tonyo (User), on Tue Apr 11 17:24:12 2006.

Quote:

Now you know why I just emit a pc-speaker beep by default.

I understand ! but on my laptop, it doesn't work...

Quote:

have you tried aplay

I tried, and it seems to be a good solution !

Thanks for all your advices.

By syfou (Core Developer & Desklet Author), on Tue Apr 11 17:51:16 2006.

If I recall correctly, Ubuntu doesn't load the pcspkr module by default, and not all laptops have them nowadays... Anyway, I am glad I could help, and I hope adesklets will prove useful to you. Yours,


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.