Verbs

Argh! here be my verbs. I'm still learning JavaScript verry verily slowly. But I actually use these jiffy Ubiquity commands interspersed between a plain text log, TiddlyWiki and just chilling out from the internet.

This command log: Inserts a date time stamp in the iso format as found in TextMate or e text-editor

code:
	CmdUtils.CreateCommand({
	//99% belongs to the source contributors, i just mashed it together
	  name: "log",
	  author: { name: "tony", email: "ccahua@gmail.com", homepage: "http://ccahua.googlepages.com"},
	  contributors: ["Atul Varma","Aza Raskin","Peter-Paul Koch"],
	  license: "MPL",
	  description: "Inserts iso date format",
	  help: "Like isoD in textmate or e-text editor, this command inserts a iso date format",
	  _isoD: function(){
            var weekday = new Array('Sun','Mon','Tue','Wed',
	'Thu','Fri','Sat');
    	var date = new Date();
            var day = leadingZero(date.getDate());
	    var month = leadingZero(date.getMonth()+1);
            var year = date.getFullYear();
	    var fullDate = year+ "." + month + "." + day;
	    var hour = leadingZero(date.getHours());
	    var minute =  leadingZero(date.getMinutes());
		var second = leadingZero(date.getSeconds());
		var weekdayTxt = weekday[date.getDay()];
function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}
	    var isoD = fullDate + " " + hour + ":" + minute + ":" + second + " " + weekdayTxt + " ";
	    return isoD;
	  },
	  preview: function( pblock ) {
	    var msg = 'Inserts a time stamp in the format: "${date}"';
	    pblock.innerHTML = CmdUtils.renderTemplate( msg, {date: this._isoD()} );
	  },

	  execute: function() {
	    CmdUtils.setSelection( this._isoD() );
	  }
	})
	

This command ts: Inserts a timestamp

code:
CmdUtils.CreateCommand({
	  name: "ts",
	  author: { name: "tony", email: "ccahua@gmail.com", homepage: "http://ccahua.googlepages.com"},
	  contributors: ["Atul Varma","Aza Raskin"],
	  license: "MPL",
	  description: "Inserts a timestamp",
	  help: "go to a text field and invoke ts for a time stamp",
	  _time: function(){
	    var date = new Date();
var hour = leadingZero(date.getHours());
	    var minute =  leadingZero(date.getMinutes());
		var second = leadingZero(date.getSeconds());
		function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}
	    var timeStamp = hour + ":" + minute + ":" + second +"h ";
	    return timeStamp;
	  },

	  preview: function( pblock ) {
	    var msg = 'Inserts a time stamp in the format: "${date}"';
	    pblock.innerHTML = CmdUtils.renderTemplate( msg, {date: this._time()} );
	  },

	  execute: function() {
	    CmdUtils.setSelection( this._time() );
	  }
});

The sample command twday: Inserts a TiddlyWiki link of today in yer tiddler edit mode

code:
	CmdUtils.CreateCommand({
	  name: "twday",
	  author: { name: "tony", email: "ccahua@gmail.com", homepage: "http://ccahua.googlepages.com"},
	  contributors: ["Atul Varma","Aza Raskin"],
	  license: "MPL",
	  description: "Inserts today's date in TiddlyWiki format",
	  help: "If you're in an edit mode text area of a tiddler, inserts today's date, formatted for the current locale.",
	  _date: function(){
	    var date = new Date();
	  var day = date.getDate();
	    var month =  date.getMonthName();
	    var myDate = "[[" + day + " " + month
	 + " " + date.getFullYear()+ "]]";
	    return myDate;
	  },

	  preview: function( pblock ) {
	    var msg = 'Inserts todays date in wiki format: "${date}"';
	    pblock.innerHTML = CmdUtils.renderTemplate( msg, {date: this._date()} );
	  },

	  execute: function() {
	    CmdUtils.setSelection( this._date() );
	  }
	})
	
	

This command chill: reminds you to chill out in the number of seconds you specify and STOP surfing the internet! My wife loves this command.

code:
CmdUtils.CreateCommand({
		  name: "chill",
		  author: { name: "tony", email: "ccahua@gmail.com", homepage: "http://ccahua.googlepages.com"},
			  contributors: ["matt the greengiant83"],
			  description: "Tells you to chill from surfing as it locks up your browser! My wife loves this command.",
			  help: "Enter chill and the number of seconds, then go do SOMETHING ELSE. You'll be reminded later to resume surfing.",
		  license: "MPL",
		  takes: {"duration": noun_arb_text},
		  preview: function( pblock, duration ) {
		    var msg = 'Chill out in {$duration} seconds.';
		    pblock.innerHTML = CmdUtils.renderTemplate( msg );
		    },
		  execute: function(duration) {
		           var secDuration = duration.text || CmdUtils.getTextSelection();
		           //check for a number
		           //im learning js so this fails if you enter a space after the chill command.
		           if(isNaN(secDuration)){
		             displayMessage("chill requires some duration to be entered");
		             return;
		           }
		           //multiply by factor of 1000 to get a second
		           var waitTime = secDuration * 1000;
		           //do a wait for secDuration cycles
		           //from matt thank you greengiant83
		           //sucky thing is it locks Ubiquity so you cant ubiq
		               function wait(msecs){
		                 var start = new Date().getTime();
		                 var cur = start;
		                   while(cur - start < msecs){
		                   cur = new Date().getTime();
		                   }
		                  }
		            wait(waitTime);
		            displayMessage("Done waiting " + secDuration + " second\(s\)");
		  }
		});