226
Programming / 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
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