Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A home made alarm clock script UNIX
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:
#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
[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.


[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 ;-)]
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)

A home made alarm clock script | 2 comments | Create New Account
Click here to return to the 'A home made alarm clock script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
"Here" files
Authored by: jantonc on Dec 12, '01 08:48:03AM
Try this
/usr/bin/osascript << SomeString
say "Hello"
say "$USER"
Everything between the first "SomeString" and the last "SomeString" becomes the standard input for the command. Shell substitution does happen. Interesting things can be accomplished once you get to the shell(Terminal) prompt.

[ Reply to This | # ]
Use cron for easier timing
Authored by: tophu on Dec 15, '01 01:27:17PM
I've been doing this for some time, not really for an alarm to wake me, but as an easy way to get invasive reminders. (e.g. "Hey idiot, today's your Mom's birthday!")

I added a Reminders directory to my ~/Library folder (of course, you can put it anywhere you want, but I thought that was best.) and created reminders in the following form:

/usr/bin/osascript -e 'set volume 6'
/usr/bin/osascript -e 'say "your message here..."'
/usr/bin/osascript -e 'set volume 1'

The command osascript -e executes one line of AppleScript. See man osascript for complete details.

I saved these files with a .command file extension, so they automatically open in Terminal when double-clicked (mostly for testing).

Once I made all my reminders, it was simply a matter of putting them in my crontab. (The cron daemon should already be running on any normally configured OS X box.) Check out man 5 crontab for a complete explanation of the crontab format, then do a crontab -e to add the entries with your terminal default visual editor(or just go get Cronnix for an Aqua GUI on it).

Once set up, you get a great reminder system.

One no-brainer safety concern: Be sure to set the permissions on your reminders so that only you can edit them. Otherwise you are giving anyone who can an open door to execute abitrary code as you.

[ Reply to This | # ]