3 # Copyright (C) 2008-2010, William Trevor King <wking@drexel.edu>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Can't drag yourself away from your software? Set an alarm!
21 # You'll have to keep your current terminal open until the alarm goes off,
22 # or the message woln't be printed to the screen.
23 # The sound will still play.
25 # Echoed text may not appear if the terminal is in curses mode (e.g. Emacs)
27 # Your message text cannot contain any shell-sensitive characters,
28 # since it gets expanded at least twice before AT sees it.
30 # Minute resolution, since that's the best `at` can do.
32 # Script is hugely larger than the actual code,
33 # but hopefully well commented inside and user friendly outside. :p
35 # Alarms should make some noise.
36 # Adapt this command to generate something on your particular system.
37 # Googling `beep wav` worked pretty well for me, or record your own :).
38 ALARM_SOUND_CMD="aplay $HOME/Music/system/towerclo.wav"
39 ECHO="/bin/echo -e" # echo command must expand '\n' to newline
46 usage: alarm <some-time> [some message]
49 <some-time> will be recognized by at (see man at).
50 'some message' will be printed to the current terminal.
51 <some-time> must be the first argument, so if your time string is
52 several words long, enclose it in quotes ('6:00 tomorrow') to keep the
53 shell from breaking it into multiple arguments."
56 # If there is no time argument, print a usage string.
59 Usage 'Incorrect number of arguments'
63 # Initialize AT_CMD, the command we will send AT, and read in arguments.
69 Append_cmd () # Add command. In case you want to add whistles to the bells ;)
72 AT_CMD="$AT_CMD\n$NEW_CMD"
75 Append_cmd "$ALARM_SOUND_CMD"
77 if [ -n "$MESSAGE" ] # if there is a non-zero message string...
78 then # ... append an $ECHO cmmd.
80 Append_cmd "$ECHO \"$MESSAGE\" > $TERMINAL_NAME"
84 then # debugging printout
90 # send the command off to at.
91 $ECHO "$AT_CMD" | at "$TIME" || Usage 'Bad time?'
93 # use `atq` to list outstanding jobs.
94 # use `at -c <job-number>` to view the script at executes for debugging.