Alarm

Discuss and share scripts and script files...
Post Reply
tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Alarm

Post by tiago »

I wrote this script to get me warned without having to install external apps as in some places I can't run tools other than the previously allowed on a white list.
Then I have this problem when the shifted time is past midnight and the alarm is broken.
Besides that script is fully functional and is being of a great help to me. To those of you who may want to use it there's a minor problem as it presents shifted date as "1h 3min 6sec" instead of "01h 03min 06sec" but that's easy for you to fix using some format(, 00).
Is there anyone out there who could please help me solving it?

Code: Select all


 $sTime = formatdate (, "hh:nn:ss");
 $hr = gettoken ($sTime, 1, ":");
 $mn = gettoken ($sTime, 2, ":");
 $sc = gettoken ($sTime, 3, ":");
 $hrC = $hr * 60;
 $hrMN = $hrC + $mn;
 $mnC = $hrMN * 60;
 $Fsec = $mnC + $sc;

  $shift = input("Enter Minutes<crlf>In how much minutes the alarm should sound?", "Only integer values please." , "15");
  $interv = input("Enter Interval<crlf>At which interval (in minutes) script must verify?", "Only integer values not greater than '$shift'." , "1");
 end $shift < $interv, "Interval '$interv' is greater than shift '$shift'!";

  $reminder = input("Enter Reminder<crlf>Any note to self?", "Enter a message in case you need a reminder." , "");

 $intervS = $interv * 60;
 $intervM = $intervS * 1000;

 $shiftC = $shift * 60;
 $shiftF = $shiftC + $Fsec;

// format duration given in seconds
  $DAYS_PER_YEAR = 365.25;
  $HOURS_PER_DAY = 24;
  $MINS_PER_HOUR = 60;
  $SECS_PER_MIN = 60;
  $sep = " ";
  $duration = "";
 
  $Secs = $shiftF;
 
  $Mins = $Secs \ $SECS_PER_MIN;
  $Hours = $Mins \ $MINS_PER_HOUR;
  $Days = $Hours \ $HOURS_PER_DAY;
  $Years = $Days \ $DAYS_PER_YEAR;
  If ($Years > 0) {
    $duration = $duration . $sep . $Years . "y";
  }
  $Days = $Days % $DAYS_PER_YEAR;
  If ($Days > 0) {
    $duration = $duration . $sep . $Days . "d";
  }
  $Hours = $Hours % $HOURS_PER_DAY;
  If ($Hours > 0) {
    $duration = $duration . $sep . $Hours . "h";
  }
  $Mins = $Mins % $MINS_PER_HOUR;
  If ($Mins > 0) {
    $duration = $duration . $sep . $Mins . "min";
  }
  $Secs = $Secs % $SECS_PER_MIN;
  If ($Secs > 0) {
    $duration = $duration . $sep . $Secs . "sec";
  }

  // cut initial sep
  $duration = substr($duration, strlen($sep));

 $ctrl = 1;

// $verify = round($shiftF / $intervS); // tried $intervM, $intervS (great!)

// $verify = $shift + 1; //most reliable

 $verify = ceil($shift / $interv);

// $verify = 10; //debug
 WHILE ($ctrl <= $verify) {

 $sTimeN = formatdate (, "hh:nn:ss");

 $hrN = gettoken ($sTimeN, 1, ":");
 $mnN = gettoken ($sTimeN, 2, ":");
 $scN = gettoken ($sTimeN, 3, ":");

 $hrCn = $hrN * 60;
 $hrMNn = $hrCn + $mnN;
 $mnCn = $hrMNn * 60;
 $FsecN = $mnCn + $scN;

 IF ($shiftF > $FsecN) { 
 $testctrl = $ctrl / 2;
 $gt = gettoken($testctrl, "2", ".");
 IF ($gt != "") { status "run: $ctrl, alarm ON - $duration ($sTime + $shift min)", "BF0000", "progress"; $ctrl++; wait($intervM); }
 ELSEIF ($gt == "") { status "run: $ctrl, alarm ON - $duration ($sTime + $shift min)", "008000"; $ctrl++; wait($intervM); }
                       }

 ELSEIF ($shiftF <= $FsecN) {  $ctrl = $verify + 1; }
                           }
 $sTimeN = formatdate (, "hh:nn:ss - yyyy/mm/dd");
//  beep; beep 500, 200; beep 600, 300; //enable/disable the beep
 IF ($reminder == "") { status "$duration has past!", "FF0000", alert; echo "Estimated: $duration<crlf>Now is     : $sTimeN<crlf>(estimated + $interv min interval)<crlf>(year/month/day)"; }
 ELSEIF ($reminder != "") { status "$duration has past! - $reminder.", "FF0000", alert; echo "Estimated: $duration<crlf>Now is     : $sTimeN<crlf>(estimated + $interv min interval)<crlf>(year/month/day)<crlf 2>Reminder:<crlf>$reminder"; }
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Alarm

Post by tiago »

The only solution I could came up with was this:

at the end of the calc of duration, replace the "1 day" indication by ">00". Not elegant and more of an easy solution. Still open to suggestions.

Code: Select all

 replace $duration, $duration, "1d ", ">00h";
If only I could minimize XYplorer's window when it's running... <sigh>
Power-hungry user!!!

Dario
Posts: 45
Joined: 20 Aug 2011 17:06

Re: Alarm

Post by Dario »

tiago wrote:I can't run tools other than the previously allowed on a white list.
I'd like to try your script, but I don't know, how it run. What does it mean, your text above.
tnx

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Alarm

Post by j_c_hallgren »

Dario wrote:
tiago wrote:I can't run tools other than the previously allowed on a white list.
I'd like to try your script, but I don't know, how it run. What does it mean, your text above.
tnx
What I believe tiago means is that he sometimes uses XY on PC's that have IT security policies that prevent usage of any software not on their official approved list...so doing a task via XY scripting is possible but installing some other software to do an alarm isn't.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: Alarm

Post by tiago »

That's it.
Power-hungry user!!!

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Alarm

Post by j_c_hallgren »

FWIW, an alarm clock on web that I found quite handy: http://www.nakedalarmclock.com/
(the name of site is just to make it memorable -- nothing else)
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

Post Reply