Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- #
- # a (very simple) recurring alarm clock for windows
- # easily converted to any other platform by replacing the call to the windows msg tool
- # all data is stored in the file itself (in the __DATA__ section at the bottom)
- # this is written in pure perl, no packages are required
- #
- # under windows I suggest using the ActiveState wperl interpreter to launch the alarm clock
- # that prevents you from having a command processor hanging around just to run the alarm clock
- # the unfortunate side effect is that you have to kill it using task manager since it never exits
- #
- #
- # Copyright (c) 2019 by James Brown
- #
- # This software is released into the public domain
- # Do with it what you will (please don't use it for evil)
- # Don't blame me if it doesn't work for you
- #
- ########################
- # config section
- ########################
- $pause = 10; # time to display the message, in seconds
- $debug = 0; # set to non-zero for verbose debug info
- ########################
- # end config
- ########################
- $dataStart = tell DATA; # save the original position
- while(1)
- {
- ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
- warn "Running at $hour:$min:$sec on day $wday\n" if ($debug);
- seek DATA, $dataStart, 0; # position to start of data section
- while(<DATA>)
- {
- chomp;
- s/\r|\n//g;
- warn "DATA: $_\n" if ($debug);
- next if (/^\s*[;#]/); # comment lines can start with pound or semi-colon
- # optionally match either a w or W or any string of digits, with or without commas
- # then a time
- # then a message
- if (/^\s*(?:([wW]|(?:\d+?(?:,\d)*,?))\s+)?(\d{1,2}):(\d{1,2})\s+(.+)/)
- {
- $d = $1;
- $h = $2;
- $m = $3;
- $msg = $4;
- $d='0,1,2,3,4,5,6' if ($d eq ''); # blank = daily
- $d='1,2,3,4,5' if ($d eq 'W'); # weekdays, Mon-Fri
- $d='0,6' if ($d eq 'w'); # weekend, Sat, Sun
- warn "day string: $d\n";
- `msg \%USERNAME\% /time:$pause "$msg"` if ($h == $hour && $m == $min && $d =~ /$wday/);
- }
- }
- warn "sleeping ...\n" if ($debug);
- sleep(60 - (time() % 60)); # sleep until the next minute
- }
- ###########################################
- # in the DATA section (below), put in all your alarms
- # times in 24 hour format
- #
- # the format of each line is
- # [d] hh:mm message
- #
- # the optional first parameter (d) is the day(s) the alarm should be active
- # this can be one or more day numbers (0=Sunday, 1=Monday, etc.) seperated by commas (but no spaces)
- # or it can be 'w' for weekend (Sat, Sun) or 'W' for weekdays (Mon-Fri)
- # (mnemonic is 'w' is shorter than 'W' because weekends are shorter than the work week)
- # leaving the day parameter off means every day (daily alarm)
- #
- # some examples
- # -------------
- # W 7:15 Time to wake up (on weekdays)
- # w 9:00 Time to wake up (on weekends)
- # 1,3,5 12:00 Team lunch (on Mon, Wed, Fri)
- # 18:30 Dinner time! (daily)
- #
- __DATA__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement