I experimenting with writing Vista/W7 gadgets. In my experiment I want to write the modification date of certain files on the system. Problem is that if I want use string manipulation functions the gadget just stops writing its output. Part of the gadget's code looks like this:
function format_lmd(lmd)
{
// Parse something like "Sun Aug 26 17:13:22 UTC+0200"
var lmdFields = lmd.split(' ');
//weekday = lmdFields[0];
//month = lmdFields[1];
//monthday = lmdFields[2];
//moment = lmdFields[3];
//return monthday+' '+month+' '+moment;
return lmd;
}
function paintGadget()
{
var fileitem = System.Shell.itemFromPath("c:\\myfile.txt");
//canvas.addTextObject(' '+fileitem.modifyDate, 'Segoe UI', 9, 'white', text_offset, 21);
var result = null;
result = ' ';
result += format_lmd(fileitem.modifyDate);
canvas.addTextObject(result, 'Segoe UI', 9, 'white', text_offset, 21);
}
The call to split (in the function format_lmd) seems to halt the script (or better: throw an exception). Although documentation seems to indicate that the split function can be used to split a string in multiple parts, it doesn't work in my case.
Questions:
- How should I correctly use the split method?
- I didn't use Javascript before so when to declare a variable with "var" and when not remains a mystery for me. Is there a good introduction to Javascript that can be used for gadgets?
- What is the best way to debug a gadget?
Thanks, Patrick
EDIT: I found out how to enable the debugger for Javascript (see http://msdn.microsoft.com/en-us/library/bb456467%28v=VS.85%29.aspx#_sidebar_overview_debugging_basic). A debug window now pops up and says "Object expected", but this doesn't really help me.