Klipfolio Dashboard 5 API

Object Timer

Object
   |
   +--Timer

Created by Klip.createTimer(), a Timer object that instructs Klipfolio Dashboard to call a specific function every interval defined in Klip.createTimer().

Example

The following sample Klip is the same as the WMI Klip in Engines.Platform, with addition of a timer to check memory once every two seconds instead of every minute.

Note: Because this Klip contains script that may be harmful to your computer, it will be blocked. To unblock it, select "Allow Blocked Script to Run" while you are in developer mode.

<klip>
   <identity>
      <title>
         API: Timer Klip
      </title>
   </identity>
   <locations>
      <icon>
         http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
      </icon>
      <banner>
         http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png   
      </banner>
   </locations>
   <setup>
      <scriptmode>
         extended
      </scriptmode>
      <enterprise>
      	true
      </enterprise>
   </setup>

   	<messages>
      		<loading>
         		Getting Memory Usage...
      		</loading>
   	</messages>
   	
	<style>
		item { 
			type:item 
		}
		
		mempercent { 
			itemcol: 1;
			noterow:1; 
			label:"Percentage";
		}
		
		memused { 
			itemcol: 2;
			noterow:2; 
			label:"Used";
		}
		
		memtotal { 
			itemcol: 3;
			noterow:3; 
			label:"Available";
		}
	</style>
   
	<klipscript>
		<![CDATA[

// Create a timer for callback every 2000 miliseconds (2 seconds)
var g_timer = createTimer (2000);

// Call getMemData() each tick of the timer
g_timer.onTick = getMemData;


function onLoad ()
{
	Items.savehistory = false;
	Items.canalert = false;
	Items.autoremove = false;
}

function getMemData ()
{
	var freekbytes = Engines.Platform.getAvailableKBytes ();
	var totalbytes = Engines.Platform.queryWMI ("SELECT * FROM Win32_PhysicalMemory", "Capacity");

	if (freekbytes.length && totalbytes.length)
	{
		var memarray = totalbytes.split (",");

		var i;
		var totalkbytes = 0;
		for (i = 0; i < memarray.length; i++)
		{
			totalkbytes += memarray[i] - 0;
		}
		totalkbytes = totalkbytes / 1024;

		var mempct = Math.round ((totalkbytes - freekbytes)/ totalkbytes * 100);

		var xml = "<item><mempercent>" + mempct + "%</membercent>" +
			  "<memused>" + (totalkbytes - freekbytes) + " KB" + 
			  "</memused><memtotal>" + freekbytes + " KB" +
			  "</memtotal></item>"; 

		Items.clear( true );
		Engines.Data.process (xml);
	}

	return true;
}

function onRefresh ()
{
	var success = getMemData();
	
	// Make sure the user can't delete or dim (visit) the webcam image
	if(Items.length)
	{
		Items[0].canvisit = false;
		Items[0].candelete = false;
	}
	
	return success;
}

	]]>
	</klipscript>
</klip>
     	

The above Klip is the same WMI Klip with the addition of two lines at the top of the Klip's JavaScript to define the timer.

 // Create a timer for callback every 2000 milliseconds (2 seconds)
 var g_timer = createTimer (2000);
 
 // Call getMemData() each tick of the timer
 g_timer.onTick = getMemData;
 

Timers give you the ability to make Klips that update the displayed webcam image, and the system monitor Klips that use the timer to keep the system information displays up to date. These are not the only ways a timer can be used, though, and we expect Klip developers will come up with some other clever and innovative ideas for timer-based Klips.


Properties Summary
 String onTick
          Specifies a function to call every timer interval.
   

Properties Detail

onTick

String onTick

Klipfolio Dashboard 5 API

© 2009 Klipfolio Inc. All Rights Reserved.