View Single Post
  #10 (permalink)  
Old 04-11-2011, 06:36 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

Forget taking it elsewhere, we can solve it here

I know you said you just wanted help and not a solution, but first, I'm assuming you've referred to the *complete* manual? You can download it in HTML for viewing on your phone, use this clickable PDF: http://www.sto-helit.de/downloads/mo...ipt-Manual.pdf, etc..

For your scheduling needs, you can would make the notification from within the script that is being scheduled. Before doing this, I advise removing the script from the Windows notifications queue first using the following command:

Code:
RemoveNotifications(applications, parameter)
For application, you'll reference MortScript.exe (full path), and for the parameter, you will need the full path and filename of your script in quotes. SystemPath() is used for both. That command ensures that you won't leave duplicates in the queue.

As far as scheduling the execution, it's not as straightforward and frankly, I'm still thinking of the most elegant way myself. My elementary instict was to do something like:

Code:
GetTime(varTmp,varTmp,varTmp,varDay,varMonth,varYear)
varSelf=SystemPath("ScriptPath") + SystemPath("ScriptName") + SystemPath("ScriptExt") +
RunAt(varYear,varMonth,varDay+1,"0","01",varSelf)
But the problem arises with the day+1 computation... it won't work all that well on April 30th trying to schedule itself for 04-31-2011 00:01, then 4-32, 4-33, etc... You would need to use some if statements but it gets ugly with the different number of days or different months, and so on.

The way around this is to use Unix timestamp and time formatting.

Code:
9.11.2  Formatted output (FormatTime)
string = FormatTime( format [, timestamp ] )
Returns the time of the timestamp, or the current time if none is given, formatted corresponding to 
the format string.
These characters will be replaced with the corresponding value:
H Hour (00-23)
h Hour (01-12)
a am/pm
A AM/PM
i Minute (00-59)
s Seconds (00-59)
d Day (01-31)
m Month (01-12)
Y Year (4 digits)
y Year (2 digits)
w Day of week (0=Sunday to 6=Saturday)
u Unix timestamp
{MM}Month name (e.g. “January”)
{M} Month name abbreviated (e.g. “Jan”)
{WW}Day of week name (e.g. “Monday”)
{W} Day of week name abbreviated (e.g. “Mon”)
All other characters remain unchanged.
Note all return values will be strings. This is to allow leading zeroes, like "02" for february, which 
is handy to combine filenames. However, it might cause troubles when using arrays. You either 
need to assign the array elements with strings (“Month["01"] = "First"”) or convert the string to a 
number, e.g. by using “FormatTime("m")*1”.
Examples:
x = FormatTime( "h:i:s a" )
x = FormatTime( "m/d/Y", TimeStamp() + 86400 )
The last line adds exactly 24hours to the current time and returns it in "04/12/2011" format. That's a bit useless to you since you'd have to parse it further. Instead, I would advise passing "u" as the format and then using that value with RunAt() for scheduling the next execution.
Code:
9.6.5  Execute application at a given time (RunAt):
RunAt( Unix timestamp, application [, parameter] )
Again, application is the Mortscript EXE and parameter is your script in quotes. The only concern I have is that if you keep rescheduling the script for 24hrs in the future, you may start seeing time added due to delays in the event that your phone is off at that time and the script is execute 6hrs late or something. Therefore, the unix timesamp() + 24hrs thing is only effective for extracting the date of the next day (not the time).

So the final hurdle involves getting tomorrow's time in Unix format, converting that time to a regular time format, changing that new time to 00:01 while leaving the d/m/y intact, change it back to Unix, and then pass that value to RunAt().

There are a couple of different ways of doing it, I'll post mine when I sit down and get my script finalized. I'd like to see what you come up with as well.
Reply With Quote
This post has been thanked 1 times.