How to Execute Scripts on a Repeating Schedule

Description

Scripts can be executed on a reoccurring schedule in desktop applications.

The code below is a script that will fire every 5 seconds. To change to 10 minutes, change the {interval} value to 600 (seconds). The event log is written to a textbox on the xdialog and to a file. See the script 'script1' below.

Copy the code below to a new script. Save the script as 'autoexec'. 'autoexec' is a special name for scripts in Alpha Anywhere. A script named 'autoexec' will execute immediately when the desktop application is first launched or when the app is opened in Alpha Anywhere.

dim log as c = ""
dim dlg_title as c
dim dlg_body as c
dim dlg_event as c
dlg_title = "Schedule"
dlg_body = <<%dlg%
{timer=playScript}
{interval=5}
This dialog will run another script called 'script1' every x seconds.;
The interval can be changed by editing the {{interval} command.;
{lf};

Event Log:;
[%M%.100,20log];
<Close>;
%dlg%
dlg_event = <<%code%
if a_dlg_button = "playScript" then
    script_play("script1")
    log = "Last execution: " + now() + crlf() + log
end if

if a_dlg_button = "Close" then
    ui_modeless_dlg_close(dlg_title)
end if
%code%
ui_modeless_dlg_box(dlg_title,dlg_body,dlg_event)

'script1' is defined below:

'this is script 1
'put your code here that you want to run every x minutes.
dir_create_recurse("c:\eventLog")
save_to_file("Script executed at: " + now() + crlf(),"c:\eventLog\events.txt",.t.)

Limitations

Desktop Applications Only

See Also