How to Execute Scripts on a Repeating Schedule


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%
This dialog will run another script called 'script1' every x seconds.;
The interval can be changed by editing the {{interval} command.;

Event Log:;
dlg_event = <<%code%
if a_dlg_button = "playScript" then
    log = "Last execution: " + now() + crlf() + log
end if

if a_dlg_button = "Close" then
end if

'script1' is defined below:

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


Desktop Applications Only

See Also