View Single Post
  #19 (permalink)  
Old 04-12-2011, 06:35 AM
quick99si's Avatar
quick99si
Halfway to VIP Status
Offline
Location: Chicago, IL
 
Join Date: Dec 2007
Posts: 631
Reputation: 1245
quick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on repquick99si is halfway to VIP status based on rep
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Re: Certain script run at a certain time

Quote:
Originally Posted by elesbb View Post
can you possibly put comments as to what each line is doing ? i think i understand the whole timestamp and unix format .. i beilieve with the IF statement you are ensuring it to be at MIDNIGHT , considering TimeStamp get the amount of seconds FROM 01/01/1970 ...

Tell me if this helps (I apologize in advance for the lengthy notes!).

Quote:
varAutoRunTime="00:01" <--- this is a variable that stores a time for daily execution. Doing this lets you easily adapt it to other scripts. You can change this to anything you want really, like 06:00 for 6AM or 18:30 for 6PM. I don't recommend 00:00 because the phone updates the calendar at that time every day. Most of my scripts are at 3AM, 6AM, etc..

varSelf = SystemPath("ScriptPath") \ SystemPath("ScriptName") & SystemPath("ScriptExt")
varMort = SystemPath("ScriptExe") \ "MortScript.exe" <--- these two variables just point to the Mortscript shell exe and your own script. It's used later to schedule a notification.

varAutoRunTimeH = part(varAutoRunTime,":",1)
varAutoRunTimeM = part(varAutoRunTime,":",2) <--- extract 2 integers from the time setting above using the colon as the separator. the H variable will have something like "00" and M will have "01" (1 minute past midnight).

If(varAutoRunTimeH < 0 OR varAutoRunTimeH > 23 OR varAutoRunTimeM < 0 OR varAutoRunTimeM > 60)
varAutoRunTimeH="07"
varAutoRunTimeH="00" <---making sure that we didn't set the time incorrectly in the first line above. H has to be between 0 and 23 inclusive, while M has to be between 0 and 59 inclusive. I guess I should have a 59 instead of a 60 in this line actually, but they'll work identically for our purposes. If you set the first line above to something like 24:70, it'll default to 7AM (07:00) because it assumes you've made a mistake. These two lines are totally optional obviously.
EndIf

varTomorrow = TimeStamp()+86400 <--- this points to a time exactly 24hrs from now. TimeStamp() returns the current time and 86400 is added, which translates to 24hrs in seconds. The time is in Unix format (seconds since 1/1/70). We need to use the Unix format so we can avoid dealing with figuring out tomorrow's date (no need to roll over months, years, Feb issues, etc..).

varTomorrowMidnight = varTomorrow - (FormatTime("H",varTomorrow)*3600) - (FormatTime("i",varTomorrow)*60) - (FormatTime("s",varTomorrow)) <--- this line computes the Unix time of tomorrow's date at midnight. It's basically tomorrow's time (24hr in the future), minus the hours/minutes/seconds past midnight so it's adjusted to 0:00:00 of tomorrow's date. If the current time is 04-12-2011 6AM, varTomorrowMidnight will add 24hrs to the current time and then subtract 6hrs (21600 seconds). The result is 04-12-2011 0:00 in Unix format.

varTomorrowSchedule = varTomorrowMidnight + (varAutoRunTimeH*3600) + (varAutoRunTimeM*60)<--- this line basically uses tomorrow's midnight time and adds whatever we set in the first line above. For you, if you're using 00:01 up there, it'll only add 1 minute (60 seconds) to varTomorrowMidnight. You can see that you can combine this line with the previous if you'd like to optimize the script - no need to go back to midnight, and then forward to a scheduled time.
Reply With Quote
This post has been thanked 1 times.