Author Topic: Schedule Wake Up with DragText 3.x  (Read 7145 times)

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 275
  • Karma: +5/-0
    • View Profile
Schedule Wake Up with DragText 3.x
« on: February 06, 2014, 03:51:35 pm »
Hello,

I use my computer to wake me up in the morning.

The excellent DragText 3.9 add convenient drag & drop functions that I sometime forget is not present elsewhere when I have to use other systems. DragText also contain a scheduler and the documentation is straight forward and mention how to set the variables, but I can't find a way to complete the setup with the script as the text for REPEAT puzzle me a bit.

"REPEAT = ON | OFF
Set the object to reopen on a regular basis. The year must have 4 digits; the month and day must have 2."

The only possible settings for REPEAT is therefore ON or OFF.

How do I set the repeat interval with the information above, or...?



The code below should create Program objects in your Utilities folder that point to a script called AxelF.cmd placed in the same folder as this script. Day, date and start time will be set, but it can't quite yet complete the setup unless you set the interval by hand and activate each scheduled Program Object.

//Jan-Erik
Code: [Select]
/*
 * Filename: wakeup.cmd
 *   Author: JAN-ERIK
 *  Created: Sun Jan 26 2014
 *  Purpose: Script to create schedule of wake up tunes.
 *  Changes:
 */

/* Load RexxUtil Library */
IF RxFuncQuery( 'SysLoadFuncs' ) THEN
DO
    CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
    CALL SysLoadFuncs
END

folder = '<WP_TOOLS>'
prefix = 'Alarm '
app = DIRECTORY()||'\AxelF.cmd'

day.1 = 'MONDAY'
day.2 = 'TUESDAY'
day.3 = 'WEDNESDAY'
day.4 = 'THURSDAY'
day.5 = 'FRIDAY'
day.6 = 'SATURDAY'
day.7 = 'SUNDAY'
day.0 = 7

/* Set the wake up Time */
day.1.t = '06:00:00'
day.2.t = '05:10:00'
day.3.t = '06:00:00'
day.4.t = '05:10:00'
day.5.t = '06:00:00'
day.6.t = '08:00:00'
day.7.t = '08:00:00'

/* Translate to your own language */
day.1.n = 'Monday'
day.2.n = 'Tuesday'
day.3.n = 'Wednesday'
day.4.n = 'Thursday'
day.5.n = 'Friday'
day.6.n = 'Saturday'
day.7.n = 'Sunday'

today = TRANSLATE( DATE( 'W' ) )
PARSE VALUE DATE( 'S' ) WITH yyyy +4 mm +2 dd
DO i = 1 TO day.0
    IF today = day.i THEN LEAVE
END
IF i < 7 THEN
DO j = i + 1 TO day.0
    CALL CreateSchedule prefix||day.j.n, folder, 'EXENAME='||app||';OBJECTID=<ALARM_'||day.j||'>;SCHEDULE=ON;DATE='||Unbase( CalcBaseDate( DATE( 'S' ) ) + j )||';TIME='||day.j.t||';REPEAT=ON;ALWAYSOPEN=ON;'
    CALL SysSleep 1
END
IF i > 2 THEN
DO j = 1 TO i
    CALL CreateSchedule prefix||day.j.n, folder, 'EXENAME='||app||';OBJECTID=<ALARM_'||day.j||'>;SCHEDULE=ON;DATE='||Unbase( CalcBaseDate( DATE( 'S' ) ) + j )||';TIME='||day.j.t||';REPEAT=ON;ALWAYSOPEN=ON;'
    CALL SysSleep 1
END
RETURN 0

CreateSchedule: PROCEDURE
/* Remove or Comment out the next line when the code has been completed */
    SAY ARG(3)
    IF SysCreateObject( 'WPProgram', ARG(1), ARG(2), ARG(3), 'U' ) THEN
        SAY '"'||ARG(1)||'" has been created'
    ELSE SAY "Couldn't create "||'"'||ARG(1)||'"'
RETURN 0

DATED: PROCEDURE
    PARSE VALUE DATE( 'S' ) WITH yyyy +4 mm +2 dd
    today = DATE( 'D' )

RETURN 0
PARSE VALUE DATE( 'S' ) WITH yyyy +4 mm +2 dd

UnBase: Procedure
    PARSE ARG x
    If x > 3652058 then Return 'BAD'
    /*  Numeric digits 14 */
    opy = 400  * ( x + 1 ) % 146097
    ddd = x + 1 - ( opy * 365 + opy % 4 - opy % 100 + opy % 400 )
    If ddd = 366 then
    Do
        NLeapYear = ( ( ( opy + 1 ) // 4 ) <> 0 )
        opy = opy + NLeapYear
        If NLeapYear then ddd = 1
    End
    If ddd = 0 then
    Do
        LeapYear = opy // 400 = 0 | ( opy // 4 = 0 & opy // 100 <> 0 )
        ddd = 365 + LeapYear
        opy = opy - 1
    End
Return ISODate( right( opy + 1, 4, 0 ) || right( ddd, 3, 0 ) )

Syntax:
    say 'At line' sigl':' errortext(rc)
Return 'BAD'

ISODate: Procedure
    Parse arg yyyy 5 ddd .
    LeapYear = yyyy // 400 = 0 | ( yyyy // 4 = 0 & yyyy // 100 <> 0 )
    If ddd > 59 + LeapYear then y = 2 - LeapYear
    Else y = 0
    z = ddd + y + 91
    m = (z * 100 ) % 3055
    d = z - ( m * 3055 ) % 100
Return yyyy'/'right( m - 2, 2, 0 )'/'right( d, 2, 0 )

CalcBaseDate: PROCEDURE
  NonLeap.   = 31
  NonLeap.0  = 12
  NonLeap.2  = 28
  NonLeap.4  = 30
  NonLeap.6  = 30
  NonLeap.9  = 30
  NonLeap.11 = 30

  parse arg cyear +4 cmonth +2 cdate

  if length( cyear ) <= 2 then
    if cyear < 80 then
      fullyear = "20" || cyear
    else
      fullyear = "19" || cyear
  else
    fullyear = cyear

  numyears = fullyear -1
  basedays = numyears * 365
  QuadCentury = numyears % 400
  Century = numyears % 100
  LeapYears = numyears % 4
  basedays = basedays + (((LeapYears - Century) + QuadCentury) - 1)

  do i = 1 to (cmonth -1)
    if i <> "2" then
      basedays = basedays + NonLeap.i
    else /* find if it's a leap year or not */
      if (fullyear // 4) > 0 then
        basedays=basedays + 28
      else
        if ((fullyear // 100) = 0) & ((fullyear // 400) > 0) then
        do
                        /* century not divisble by 400                */
          basedays = basedays + 28
        end /* if */
        else
        do
                        /* quad century or regular leap year          */
          basedays = basedays + 29
        end /* else */
  end /* do */

  basedays = basedays + cdate
return basedays
« Last Edit: February 06, 2014, 04:13:01 pm by Jan-Erik Lärka »

Doug Bissett

  • Hero Member
  • *****
  • Posts: 1593
  • Karma: +4/-2
    • View Profile
Re: Schedule Wake Up with DragText 3.x
« Reply #1 on: February 07, 2014, 12:18:12 am »
Quote
I use my computer to wake me up in the morning.

I have considered doing that. The local radio is pretty bad.

Quote
How do I set the repeat interval with the information above, or...?

I don't know how to do what you want to do, but I wouldn't even think about using DragText to do it. Dragtext is good for consistently doing something, on a repeatable basis. That is, "set and forget". It seems that you want to do something different, on different days (and probably add more exceptions for holidays etc.). If I was going to do that, I would just use REXX to do it. You already have the basic script, just add a command to start PM123, with a playlist, or URL, at the appropriate time.

My "plan" would be to use PM123, to tune in an internet radio station, which can be done with a simple command. You could also use a local playlist for your own music files. Then, I would kill PM123 after a timeout period (1 or 2 hours), and have a way to tell it to close earlier. You may also want a "Sleep button".

My "problem" is that I really don't want to have a computer in my bedroom. What I would really like to have, is an FM transmitter, that could be attached to my main computer, so I could listen using my existing clock radio (which is actually a piece of junk).

I have also looked at the BOSE radio, that has a WiFi adapter in it. Apparently it can use a normal URL, or it can use a local system, if it has an appropriate program (Mediatomb will probably do it). I am not sure how programmable the radio is, as far as changing the wake up time for special days.

Just some thoughts...

Jan-Erik Lärka

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 275
  • Karma: +5/-0
    • View Profile
Re: Schedule Wake Up with DragText 3.x
« Reply #2 on: February 07, 2014, 07:56:49 am »
Quote
How do I set the repeat interval with the information above, or...?

I don't know how to do what you want to do, but I wouldn't even think about using DragText to do it. Dragtext is good for consistently doing something, on a repeatable basis. That is, "set and forget". It seems that you want to do something different, on different days (and probably add more exceptions for holidays etc.). If I was going to do that, I would just use REXX to do it. You already have the basic script, just add a command to start PM123, with a playlist, or URL, at the appropriate time.

Set and forget is exactly what the script is supposed to do and does, my weeks look all the same.
REXX is a wonderful scripting language, but in itself lack a scheduler.
The thing is that I don't want to recreate the program objects by hand for every test installation and new beta release of eCS that I try.  ;)

If there's a way to add it, then there's a way to remove the schedule as well, delete the program object or rewrite/update it, so it shouldn't be a problem once I get the info to create similar Objects for other use.

My "plan" would be to use PM123, to tune in an internet radio station, which can be done with a simple command. You could also use a local playlist for your own music files. Then, I would kill PM123 after a timeout period (1 or 2 hours), and have a way to tell it to close earlier. You may also want a "Sleep button".

Ok, that is a good plan, especially if one can hug the pillow for an hour or two.

Wireless small touch screen next to the bed as Photo Frame (screen saver of eCS) + speakers.
A giant "One Button Snooze/Sleep"-skin for PM123

My "problem" is that I really don't want to have a computer in my bedroom. What I would really like to have, is an FM transmitter, that could be attached to my main computer, so I could listen using my existing clock radio (which is actually a piece of junk).

That would be just great to have, because my clock radio is just as bad.
Show time, play music and got a sleep/snooze button.

I have also looked at the BOSE radio, that has a WiFi adapter in it. Apparently it can use a normal URL, or it can use a local system, if it has an appropriate program (Mediatomb will probably do it). I am not sure how programmable the radio is, as far as changing the wake up time for special days.

Just some thoughts...

Great thoughts!

Doug Bissett

  • Hero Member
  • *****
  • Posts: 1593
  • Karma: +4/-2
    • View Profile
Re: Schedule Wake Up with DragText 3.x
« Reply #3 on: February 07, 2014, 08:34:29 pm »
Quote
REXX is a wonderful scripting language, but in itself lack a scheduler.

Actually, it isn't all that difficult to program a simple scheduler, but an alternative would be to use DragText to start the REXX, just before the first wakeup time (05:10), every day. Trigger your REXX to check what day it is. If it is a day when the alarm is supposed to happen then, wait for the proper time, and trigger the alarm (turn on the music, make noise, whatever). If it is a day to wake up at 06:00, or 08:00, set the appropriate sleep time, sleep, then trigger the alarm. A table of special days could also allow a different time for holidays (I would suggest that an alarm at 05:10, on New Years Day, would probably not be ideal).   :)

If you want to use DragText, to trigger something at different times, you would need to have multiple icons (one for each day), or you would need to use REXX to change the schedule in that one icon, every day. The repeat time would need to change, or the trigger time would need to change. I don't know of any way to change those things with a program (WPTOOLS would be the way to do it, that I know about, but it doesn't know about those settings). You would still need to run some REXX (or something else) to make the change, every day, and that REXX would need to do the time math to figure out the proper settings. Easier to just run the REXX, and put it to sleep for the appropriate time periods, before or after checking the schedule. Of course, it would need to synchronize itself, when the program starts (after a boot, or whatever), and set an appropriate initial sleep time.

Quote
If there's a way to add it, then there's a way to remove the schedule as well, delete the program object or rewrite/update it, so it shouldn't be a problem once I get the info to create similar Objects for other use.

The WPTOOLS source is at netlabs: ftp://ftp.netlabs.org/pub/wptools/. Inspecting that, may give you some idea of what to look for. Rich Walsh wrote DragText, but he seems to have left the OS/2 community. A polite message to him, might get some information.