3

I configured my applications to beep when done (helps me multitask on long runs). On windows it was simple:

def beep_please():
    """Beep on Windows"""
    if os.name == 'nt':
        import winsound #@UnresolvedImport
        winsound.MessageBeep(winsound.MB_ICONEXCLAMATION)

import atexit
atexit.register(beep_please)

The problem is I recently switched to Linux and simple beeping doesn't work. Printing '\a' doesn't work either. Help?

Tal Weiss
  • 8,889
  • 8
  • 54
  • 62
  • related: http://stackoverflow.com/q/974071/4279 – jfs Jan 03 '11 at 12:29
  • See the answer to this question: http://stackoverflow.com/questions/6445425/can-eclipse-notify-me-when-a-task-has-finished-running A kind soul provided source code for an eclipse plugin that beeps when a job has completed. – Amanda S Jun 23 '11 at 22:53

2 Answers2

0

Root cause is that most modern Linux distros turn off the annoying default "beep".
Potential solutions are using pygame, or using one of the installed "players" directly.

Using Pygame looks like this:

import pygame

pygame.init()
pygame.mixer.music.load("my_sound_file.ogg")
pygame.mixer.music.play()
pygame.event.wait()

But I did not want the new external dependency for the sake of a non-run-time utility, so what I ended up doing is:

import os
os.system("/usr/bin/canberra-gtk-play --id='system-ready'")

There are plenty of other sound files in the Ubuntu theme:

ls /usr/share/sounds/ubuntu/stereo
Tal Weiss
  • 8,889
  • 8
  • 54
  • 62
0

Try doing sys.stdout.write('\007') instead of print '\a'

albertov
  • 2,314
  • 20
  • 15
  • I get a rectangle square with 0007 in it... Eclipse 3.6.1 and Ubuntu 10.10. – Tal Weiss Jan 03 '11 at 10:15
  • Hmm, perhaps stdout is not pointing to a tty. Try `open('/dev/pty0','w').write('\007')`. However, this is not robust as it assumes you've got /dev/pty0 open. I don't know how to make it better... perhaps /dev/tty0? – albertov Jan 03 '11 at 10:18
  • Both result in IOError: `[Errno 13] Permission denied: '/dev/tty0'` – Tal Weiss Jan 03 '11 at 10:34
  • Outside eclipse, printing `'\a'` doesn't do anything. And writing to pty0 and tty0 resulted in the same Permission Denied error. Sudoing the above results in nothing as well. – Tal Weiss Jan 03 '11 at 10:46
  • `print '\007'` *outside* eclipse – albertov Jan 03 '11 at 10:55
  • @albertov : Nada. It is like my Ubuntu does not have any beeps (sound in general works, of course). – Tal Weiss Jan 05 '11 at 06:41