Action Directory / Blog

Install

Inserts date, time and titel as a Markdown header at the top of your document

Shared by Blog

Script

// Inserts date, time and titel as a heading at the beginning of your document. Also inserts
// new line to start typing your 'Zettel' notes. Based on the Log action for 1Writer.

var timestamp = function() {
	function pad2(n) { return n < 10 ? '0' + n : n };

	var date = new Date();
	var timestamp = date.getFullYear().toString() + '-' + pad2(date.getMonth() + 1)
	+ '-' + pad2( date.getDate()) + ' ' + pad2( date.getHours() ) + ':' + pad2( date.getMinutes() );

	return( timestamp );
}

// Insert	 date & time at beginning of document as a Markdown header and position cursor just after heading so that you're ready to type.
var heading = '## ' + timestamp()
ui.input('nome della sezione', null, 'Nome della sezione', function(zettel) {
    if (zettel) {
        editor.replaceSelection(' '+zettel+'\n\n\n');
    }
});

editor.replaceTextInRange(0, 0, heading );
editor.setSelectedRange(heading.length, heading.length-2);