Action Directory / Journal Entry

Install

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

Shared by @chiefdoofficer

Script

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

// Format day. e.g. Sunday Feb 7, 2016
var now = new Date();
var hh = now.getHours();
var min = now.getMinutes();
var dd = now.getDate();
var mm = now.getMonth()+1;
var yyyy = now.getYear()+1900;
var dayOfWeek = now.getDay();
var shortMonthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "August", "September", "October", "Nov", "Dec"
];
var daysOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day = daysOfWeek[dayOfWeek];

var today = day + ' ' + shortMonthNames[now.getMonth()] + ' ' + now.getDate() + ', ' + yyyy;

// Format time. e.g. 7:12am
if(hh<12) {
    min=min+'am'
} else {
    min=min+'pm'
}

if(hh>=13) {
    hh=hh-12
}

var time = hh+':'+min;

// 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 = '## ' + today + ' ' + time + '\n\n\n';
editor.replaceTextInRange(0, 0, heading);
editor.setSelectedRange(heading.length-2, heading.length-2);