The Engines.Platform object enables a Klip to query the Windows Management Interface.
Klip Security Model
Using the API calls below requires running with developer mode enabled and having the XML <scriptmode>extended</scriptmode> within the Klip's <setup> block, as shown below.
<setup>
<scriptmode>
extended
</scriptmode>
</setup>
In order to use this object without the Developer Mode turned on, you must have your Klip digitally signed by Klipfolio Inc.
WMI Example
The following Klip makes a call to WMI to monitor the current memory once a minute.
<klip>
<identity>
<title>
API: WMI Interface
</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>
</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[
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>
| Function Summary | |
function
|
getAvailableKBytes()
Returns the number of available memory in KiloBytes. |
function
|
getCPUUsage()
|
function
|
getClipboardURL()
|
function
|
launchDefaultBrowser( <String> url )
|
function
|
launchDefaultMailClient()
|
function
|
queryWMI( <String> query, <String> row )
|
| Function Detail |
getAvailableKBytes
function getAvailableKBytes()
- Returns the number of available memory in KiloBytes.
-
Returns:
-
number of available memory in KiloBytes.
getCPUUsage
function getCPUUsage()
-
Returns:
-
current CPU usage as a percentage
getClipboardURL
function getClipboardURL()
-
Returns:
-
the URL that is stored on the clipboard
launchDefaultBrowser
function launchDefaultBrowser( <String> url )
-
Parameters:
url - URL of the website to open in the default browser
launchDefaultMailClient
function launchDefaultMailClient()
queryWMI
function queryWMI( <String> query, <String> row )
More information on WMI is available from Microsoft Library.
Example
For example, WMI query returns the total size of memory.
var totalbytes = Engines.Platform.queryWMI (
"SELECT * FROM Win32_PhysicalMemory", "Capacity");
-
Parameters:
query - SQL query into a WMI table.
row - Row of desired data.
-
Returns:
-
results of query.
|
Klipfolio Dashboard 5 API | ||||||||
| PREV OBJECT NEXT OBJECT | FRAMES NO FRAMES | ||||||||
| SUMMARY: PROPERTY | FUNCTION | DETAIL: PROPERTY | FUNCTION | ||||||||
© 2009 Klipfolio Inc. All Rights Reserved.
