Friday, January 2, 2009

Simple Motherboard Beep Script for Windows

Problem:
So you want to be notified by sound when something is triggered (process starts/stops, file accessed, etc). Well, you could just open a file and let it play, but what if you have headphones plugged in? Then you won't hear anything (unless the volume is extremely loud... but if you listen to it that loud I'm sure you wouldn't hear it anyways). So... how do you make your motherboard beep at the frequency, duration, spacing, and count you desire? Python.

Solution:
So Python has a wonderful module to do just this: winsound. I personally just wanted something that I could import or call from the command line to notify me of an event. So I wrote a little script to do this. I also wrote a script for py2exe.

The Script:
bell.py
So as you can see the script is only about 20 lines, but you can specify from the command line the number of beeps, duration, frequency, and spacing. I use this all the time for process monitoring, etc. It is dependable because unlike printing the \a character or chr(7) you have control over the beep AND it is dependable (doesn't depend on your terminal settings). To convert this python script to exe I use py2exe
bellexe.py

This simply creates an exe that can be called from any program within any language. I use it a lot in automated testing.

Just run:

from the command line to create the exe.

0 comments:

Post a Comment