Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. #
  3. # a (very simple) recurring alarm clock for windows
  4. # easily converted to any other platform by replacing the call to the windows msg tool
  5. # all data is stored in the file itself (in the __DATA__ section at the bottom)
  6. # this is written in pure perl, no packages are required
  7. #
  8. # under windows I suggest using the ActiveState wperl interpreter to launch the alarm clock
  9. # that prevents you from having a command processor hanging around just to run the alarm clock
  10. # the unfortunate side effect is that you have to kill it using task manager since it never exits
  11. #
  12.  
  13. #
  14. # Copyright (c) 2019 by James Brown
  15. #
  16. # This software is released into the public domain
  17. # Do with it what you will (please don't use it for evil)
  18. # Don't blame me if it doesn't work for you
  19. #
  20.  
  21.  
  22.  
  23. ########################
  24. # config section
  25. ########################
  26. $pause = 10; # time to display the message, in seconds
  27.  
  28. $debug = 0; # set to non-zero for verbose debug info
  29.  
  30. ########################
  31. # end config
  32. ########################
  33.  
  34.  
  35.  
  36. $dataStart = tell DATA; # save the original position
  37.  
  38. while(1)
  39. {
  40. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
  41. warn "Running at $hour:$min:$sec on day $wday\n" if ($debug);
  42.  
  43. seek DATA, $dataStart, 0; # position to start of data section
  44.  
  45. while(<DATA>)
  46. {
  47. chomp;
  48. s/\r|\n//g;
  49.  
  50. warn "DATA: $_\n" if ($debug);
  51.  
  52. next if (/^\s*[;#]/); # comment lines can start with pound or semi-colon
  53.  
  54. # optionally match either a w or W or any string of digits, with or without commas
  55. # then a time
  56. # then a message
  57. if (/^\s*(?:([wW]|(?:\d+?(?:,\d)*,?))\s+)?(\d{1,2}):(\d{1,2})\s+(.+)/)
  58. {
  59. $d = $1;
  60. $h = $2;
  61. $m = $3;
  62. $msg = $4;
  63.  
  64. $d='0,1,2,3,4,5,6' if ($d eq ''); # blank = daily
  65. $d='1,2,3,4,5' if ($d eq 'W'); # weekdays, Mon-Fri
  66. $d='0,6' if ($d eq 'w'); # weekend, Sat, Sun
  67.  
  68. warn "day string: $d\n";
  69.  
  70. `msg \%USERNAME\% /time:$pause "$msg"` if ($h == $hour && $m == $min && $d =~ /$wday/);
  71. }
  72. }
  73.  
  74. warn "sleeping ...\n" if ($debug);
  75. sleep(60 - (time() % 60)); # sleep until the next minute
  76. }
  77.  
  78.  
  79. ###########################################
  80. # in the DATA section (below), put in all your alarms
  81. # times in 24 hour format
  82. #
  83. # the format of each line is
  84. # [d] hh:mm message
  85. #
  86. # the optional first parameter (d) is the day(s) the alarm should be active
  87. # this can be one or more day numbers (0=Sunday, 1=Monday, etc.) seperated by commas (but no spaces)
  88. # or it can be 'w' for weekend (Sat, Sun) or 'W' for weekdays (Mon-Fri)
  89. # (mnemonic is 'w' is shorter than 'W' because weekends are shorter than the work week)
  90. # leaving the day parameter off means every day (daily alarm)
  91. #
  92. # some examples
  93. # -------------
  94. # W 7:15 Time to wake up (on weekdays)
  95. # w 9:00 Time to wake up (on weekends)
  96. # 1,3,5 12:00 Team lunch (on Mon, Wed, Fri)
  97. # 18:30 Dinner time! (daily)
  98. #
  99.  
  100. __DATA__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement