Monday, November 08, 2010 at 12:04 AM.


on runScriptsFolder () {
		<<12/28/09; 8:29:31 AM by DW
			<<Implement Scripts folder, a sub-folder of Guest Databases/ops that contains scripts that run every minute, every hour and once every night.
	local (basepath = "/ops/scripts/");
	on runFolder (name) {
		local (folder = frontier.getsubfolder (basepath + name + "/"), f, adrcounter);
		file.surefilepath (folder + "xxx");
		bundle { //set adrcounter
			local (capname = string.upper (name [1]) + string.delete (name, 1, 1));
			adrcounter = @user.opmlEditor.stats.runScriptsFolder.["ct" + capname + "Scripts"];
			if not defined (adrcounter^) {
				adrcounter^ = 0}};
		fileloop (f in folder) {
			try {
				local (s = string (file.readWholeFile (f)));
				s = string.replaceall (s, "\n", "");
				evaluate (s);
			else {
				new (tabletype, @user.opmlEditor.stats.runScriptsFolder.lastScriptError);
				user.opmlEditor.stats.runScriptsFolder.lastScriptError.s = tryerror;
				user.opmlEditor.stats.runScriptsFolder.lastScriptError.when = ();
				user.opmlEditor.stats.runScriptsFolder.lastScriptError.f = f}}};
	if user.opmlEditor.prefs.flScriptsFolderEnabled {
		if file.exists (frontier.getsubfolder ("/ops/scripts/")) {
			local (now = (), day, month, year, hour, minute, second);
			date.get (now, @day, @month, @year, @hour, @minute, @second);
			runFolder ("everyMinute");
			if hour != user.opmlEditor.stats.runScriptsFolder.lastHourlyScriptHour {
				user.opmlEditor.stats.runScriptsFolder.lastHourlyScriptHour = hour;
				runFolder ("hourly")};
			if not date.sameday (now, user.opmlEditor.stats.runScriptsFolder.whenLastOverNightScriptRun) {
				user.opmlEditor.stats.runScriptsFolder.whenLastOverNightScriptRun = now;
				runFolder ("overnight")}}}};
bundle { //test code
	runScriptsFolder ()}

This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.