PROVISIO DevBlog

Using the External Script Option of SiteKiosk to Automate Processes

SiteKiosk allows you to run an external script, that you can use to automate processes within SiteKiosk. The external script can contain the SiteKiosk Object Model as well as Wsript. That enables you to script a broad spectrum of tasks.

The example we want to build, will demonstrate an automated Gmail login, that will work with the IE and Chrome browser engines of SiteKiosk.

Our example code looks like this:

//Helper variable to prevent multiple SendKeys at once
var currently_sending_keys = false;

//Initialization of the WScript Shell object used for sending keys
var objShell = new ActiveXObject("WScript.Shell");

//OnMessage event fired by the browser used to start looking for the login page
SiteKiosk.Logfile.OnMessage = OnMessage;

//Handling the OnMessage event
function OnMessage(seq, time, utcoff, awtype, awlevel, facility, text){  
   //Check the navigation to identify the login page and whether the script is already sending keys
   if((text === "Navigation: http://www.gmail.com/" || text === "Navigation: http://gmail.com/") && !currently_sending_keys){
	   //Start sending keys so set the helper variable to true
	   currently_sending_keys = true;
	   //Wait a short period of time to give the page time to load and then send the user name
	   SiteKiosk.Scheduler.AddDelayedEvent(1500, SendTheUsername);
   }
}

//Send the user name
function SendTheUsername(eventID){
	objShell.SendKeys("username@gmail.com");
	objShell.SendKeys("{enter}");
	//Wait a short period of time to give the page time to the password part and then send the password
	SiteKiosk.Scheduler.AddDelayedEvent(1500, SendThePassword);
}

//Send the password
function SendThePassword(eventID){
	objShell.SendKeys("password");
	objShell.SendKeys("{enter}");
	//We are done sending keys so set the helper variable to false
	currently_sending_keys = false;
}

Let us have a closer look at some parts of the script.

...
//Handling the OnMessage event
function OnMessage(seq, time, utcoff, awtype, awlevel, facility, text){  
   //Check the navigation to identify the login page and whether the script is already sending keys
   if((text === "Navigation: http://www.gmail.com/" || text === "Navigation: http://gmail.com/") && !currently_sending_keys){
...

The script uses the OnMessage event of the SiteKiosk Object Model to track navigations. If it finds matching navigations to either www.gmail.com or gmail.com and it is currently not sending keys it triggers the automated login.

...
SiteKiosk.Scheduler.AddDelayedEvent(1500, SendTheUsername);
...

Utilizing the AddDelayedEvent method, the script gives the page some time to load. You may need to adjust the time depending on your Internet connection. The function to send the first set of keys for the user name of the Gmail login process is called next.

...
objShell.SendKeys("username@gmail.com");
...

The SendKeys method of the WScript Shell object is used to send key strokes to the browser. First the user name, then the enter key to trigger the password request. Finally the script starts a similar process for the password input mask.

Save the above example code as a javascript file (e.g. automated_gmail_login.js), preferably in the html subfolder of your SiteKiosk installation. Now in the SiteKiosk configuration you have to add the file as an external script. Go to Start Page & Browser and click on the Advanced button. Now you can tick the option that SiteKiosk should execute the script on startup.

Save the configuration and for testing purposes use the Run Once Mode of SiteKiosk. Type in gmail.com or www.gmail.com in the address field of the SiteKiosk browser. The script will attempt to make an automated login with the provided user name and password. Note that the above example script may stop working if the Gmail page layout changes.