Friday, April 26, 2013

How I Got My Computer to Chime

It all started with a blog post by Sacha Chua that made me think, "I bet there's an app for that."  She described how she set up her smart phone to vibrate every half hour.

Soon after, I found Chime Time, by Hyperfine, which turned my tablet into an Aberdeen mantel clock.  And I loved the idea of chimes and bells so much that I also installed Bodhi Timer, by Yuttadhammo, which can be set up as a timer and play a variety of tones, including singing bowl, when the time is up.

Chime Time starts up automatically when Android starts up.  But Bodhi Timer does not, so I start it in the morning.  I might set it to go off every 15 minutes starting at about 7 minutes after the hour (or any 15-minute interval afterwards), or every 10 minutes starting at 5 after the hour (or any 10-minute interval afterwards), depending on when I can remember to do it.

Having bells and chimes sound off every so often reminds me to live in the present.  When I hear the sound I ask myself whether I'm using time mindfully.

However, my wife absolutely hates it.

Anyway, after enjoying this for a few days on my tablet, I wondered if there were something similar that I could use on my work computer.  I didn't feel like running the tablet just to have it make noise.

That motivated me to search on SourceForge, where I found TeaTimer.  But TeaTimer would pop up an alert box at the end of each interval because it was really intended as a timer for steeping tea.  So I decided to write my own in Visual Basic 6.

I wrote a simple application that would simply play a WAV file whenever it was invoked.  I chose chimes.wav from Microsoft Office, although I'm sure there's an equivalent from OpenOffice, as well.  Then I set a job in Task Scheduler to call it every 15 minutes.  There is a special trick to pulling this off, though, because while my program worked fine when invoked interactively, it refused to work when triggered by Task Scheduler.

I found the solution on the Microsoft Support website: http://support.microsoft.com/kb/86281.

Here's the source code in its entirety, comments removed for clarity:
Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Const SND_SYNC = &H0
Public Const SND_ASYNC = &H1
Public Const SND_NODEFAULT = &H2
Public Const SND_LOOP = &H8
Public Const SND_NOSTOP = &H10
'Here are explanations for the parameters: (removed)
Private Sub Main()
    Dim SoundName$
    Dim x%, wFlags%
   
    SoundName$ = "C:\Program Files (x86)\Microsoft Office\OFFICE11\MEDIA\CHIMES.WAV"
    wFlags% = SND_NODEFAULT ' Or SND_ASYNC
    x% = sndPlaySound(SoundName$, wFlags%)

End Sub

No comments: