var FileWatch = function(filename, duration) { this.file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); this.file.initWithPath(filename); this.duration = duration; }; FileWatch.prototype = { iid: null, lastTime: null, watch: function() { this.lastTime = (new Date()).getTime(); var self = this; this.iid = setInterval(function() { self.watchFile(); }, this.duration * 1000); }, watchFile: function() { if (this.file.lastModifiedTime - this.lastTime > 0) { this.log("modified"); } this.lastTime = (new Date()).getTime(); }, log: function(message) { Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(message); }, unwatch: function() { clearInterval(this.iid); } };