A home made alarm clock script

Dec 10, '01 08:10:38PM

Contributed by: Anonymous

This hint covers using a combination of the UNIX shell and AppleScript to make a simple but effective alarm clock. If you are like me, you are a geek that never turns off his/her computer. ;-) My iMac runs Seti@home and another distributed computing project all the time, so I rarely turn it off.

I figured out how to make a simple alarm using the terminal and AppleScript to cause a voice to start talking in the morning to wake me up.

Read the rest if this interests you.

The interesting part is you can make the voice say anything you want it to. Robots Inc..

With Pico or Emacs or vi (or BBEdit) create a shell script. Our example will be an 8-hour timer:

#!/bin/sh
#first line establishes interval in seconds until the rest is to be executed
sleep 28800
#the actual alarm
echo 'say "Wake up Phil. Rise and shine. Wake up now.
Phil it is time to wake up. Can you hear me? Get out of bed."' | /usr/bin/osascript
exit
[Editor's note: The "echo" line is shown on two lines; type it as one continuous line]

To run it (in the terminal) make sure it has the execute permission set (chmod 755 or 775), is in a directory in your $PATH variable, and has a name. Mine is just called "8":
[localhost:~] yournamehere% 8 &
The ampersand makes it a background process and frees the terminal to do other things. The part after "echo 'say" is left to your own imagination. The whole command uses a "|" pipe to send the output to the AppleScript event handler.

You can open the "Speech" item in System Prefs to choose which one of the voices you want.

Enjoy

[Editor's note: Although I haven't tried it, I imagine you could also leave out the "sleep" portion of the script, and use a cron job to run the script at a certain time each day...I think ;-)]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20011210201038211