On-A-Timer
Run Script On a TimerThe Timer (Command) executes the TimerProc macro, and the combination can be used to run a script every n seconds.
The following example shows a timer procedure that runs every 2 seconds to check if a data file on disk has been modified, and it is then re-imported if new.
In order to run this scipt example, perform the following steps first:
timer -k;
// Set up the TimerProc macro def TimerProc { // Check if file exists, and quit if it does not string str$="c:\temp\mydata.dat"; if(0 == exist(str$) ) return; // Get date/time of file on disk double dtDisk = exist(str$,5); // Run script on data book // Assuming here that book short name is mydata win -o mydata { // Get date/time of last import double dtLast = page.info.system.import.filedate; // If file on disk is newer, then re-import the file if( dtDisk > dtLast ) reimport; } } // Set TimerProc to be executed every 2 seconds timer 2;
The Samples\LabTalk Script Examples subfolder has a sample Origin Project named Reimport File Using Timer.OPJ which has script similar to above set up. You can open this OPJ to view the script and try this feature.