Action Directory / Append Log Entry (full date)

Install

Inserts a headline with date and time and new line at end of file

Shared by Bernhard

Script

// Insert date and 24h time at end of file
function appendLogEntry(prefix) {

var daysOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
function pad2(str){ 
 return ('0' + str).slice(-2);
}
function cursorToEnd() {
  var content = editor.getText();
  editor.setSelectedRange(content.length);
}
var now = new Date();
entry  = prefix + now.getFullYear() + '-'
         + pad2(now.getMonth()+1) + '-'
         + pad2(now.getDate()) +' ('
         + daysOfWeek[now.getDay()] + ') '
         + pad2(now.getHours()) + ':' 
         + pad2(now.getMinutes()) +' \n\n';
cursorToEnd();
editor.replaceSelection(entry);
cursorToEnd();

}

appendLogEntry('## ');