How to ring the system bell with Ruby (Win32)

There a couple ways to accomplish this. My application required the first option because the second wouldn’t work from within Eclipse.

require "win32/sound"
include Win32

Sound.play(SystemAsterisk", Sound::ALIAS) # play system asterisk sound
Sound.beep(600,200) # play a beep 600 hertz for 200 milliseconds

or

irb(main):001:0> puts "\a"
=> nil
irb(main):002:0>

The Ruby on Windows blog has some additional info about Adding Sound to Your Ruby Apps.

(Side note: I’ve posted this because it was almost impossible to find by googling. See for yourself what happens when you search for “ruby ring a bell”- you’ll get about 200,000 false positives.)

This entry was posted in ruby. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>