how to get a beep, OS independent ?

Grant Edwards grante at
Mon Dec 8 05:27:31 CET 2008

On 2008-12-07, Peter Pearson <ppearson at nowhere.invalid> wrote:
> On Sun, 07 Dec 2008 00:40:53 +0100, Stef Mientki wrote:
>> I want to give a small beep, for windows there's message-beep,
>> and there seems to be something like " curses" , but that
>> package seems to be totally broken in P2.5 for windows.
>> Any other suggestions ?
> Many people have suggested sending an ASCII 07 to your
> terminal window, but sometimes you don't have a terminal
> window.

Some terminal windows don't beep when they receive a BEL
character. Some flash, some do nothing at all -- but that's the
user's decision. I believe sending a BEL to stdout is the
accepted standard for command-line applications.

> Then there's the question of using the sound card versus using
> the PC speaker.

Assuming the computer has at lease one of the two (some of mine

> Too complicated for me.

Cross-platform programming is indeed complicated.

> I used a kluge: a short C program that beeps the way I want,
> in this case using ioctl(fd,KDMKTONE,arg) on /dev/tty0 (this
> is Linux).  The program has enough privileges to execute even
> when run by unprivileged users, and of course can be invoked
> by whatever language you're working in.

That would seem to make the machine on which the ioctl() call
is executed beep (assuming it can beep).  What if you're ssh'ed
into the machine or running a remote X server?  What if the
user is deaf?  One would presume the intent was to alert the
person running the program to some condition that needs

If it's a command-line appliction, output a BEL character to
stderr.  That's the standard way to alert the user.  If the
user has her terminal configured to do something else (e.g.
flash), then that's her decision and you shouldn't try to
override it.

If it's an X11 application, then use the Xlib call to request
that the X server alert the user (usually with a "beep").

I've no idea what one does under Windows or MacOS, but I'm sure
they have their "standards" as well.


More information about the Python-list mailing list