VWorks User Guide : Setting up and using the Watcher tool : Setting up the Watcher configuration file

Setting up the Watcher configuration file
About this topic
This topic assumes that you know how to write programs in JavaScript or have basic programming knowledge. You must also have VWorks administrator or technician privileges.
Creating the configuration file
Watcher requires a single configuration file (.ini) that contains one entry (monitoring condition) per line. Each monitoring condition entry must consist of the following four values separated by commas:
<folder to monitor>,<file filter>,<JavaScript file location>, <JavaScript function>
Figure. Watcher configuration file showing an example of the four comma-separated values
 
 
Configuration example—Monitoring one folder for one file type
In the following example, Watcher will monitor the Inputs folder for the file type .xml. When an .xml file is added to the folder, Watcher will run myscript.js and call the main function. The function main must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
C:/VWorks Workspace/Inputs,.xml,C:/VWorks Workspace/Scripts/myscript.js, main
function main(input_file){
print("in main: " + input_file)
}
Configuration example—Monitoring one folder for more than one file type
The Watcher configuration file (.ini) can specify multiple monitoring conditions, but each condition must be stated on a single line and consist of the four comma-separated values.
In the following example, Watcher will monitor the Inputs folder for the file types .xml and .rst (runset). When either file is added to the folder, Watcher runs myscript.js and calls the corresponding JavaScript function for the file type. The functions mainXML and mainRST must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
Figure. Watcher configuration file example specifying one folder and two file types for monitoring
 
For this example, the myscript.js file would contain the following code:
function mainXML(input_file){
print("in mainXML: " + input_file)
}
function mainRST(input_file){
print("in mainRST: " + input_file)
}
Configuration example—Monitoring more than one folder
You can specify that more than one folder be monitored and run different scripts for different file types that appear in each folder.
Figure. Watcher configuration file example specifying two folders and two file types for monitoring
 
Using the same script from the previous example, this configuration file would do the following:
Monitor the InputsXML folder for new .xml files, and then call the mainXML function. The mainXML function must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
Monitor the InputsRST folder for new .rst files, and then call the mainRST function. The mainRST function must be defined to take in one parameter, the full path of the file that has appeared in the folder to be watched.
Specifying the configuration file location
To set the configuration file location:
1
Select Tools > Options. The Options dialog box opens.
 
2
In the Watcher Options area, click the field next to Path to Watcher configuration file, and then click the button that appears.
3
In the Open dialog box, select the desired location and click Open.
4
In the Options dialog box, verify the new path, and then click OK.
Related information