Action Directory / Log

Install

Inserts date and time at cursor and adds new line to start typing log notes

Shared by

Script

// Inserts day, date and 12 hr time; inserts new line to start typing your log notes. Inspiration from similar scripts in other apps.

// Insert day yyyy-mm-dd hh:min:sec
var now = new Date();
var hh = now.getHours();
var min = now.getMinutes();
var sec = now.getSeconds();
var dd = now.getDate();
var mm = now.getMonth()+1;
var yyyy = now.getYear()+1900;
var dayOfWeek = now.getDay();
var daysOfWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var day = daysOfWeek[dayOfWeek];

if(dd<10) {
    dd='0'+dd
} 

if(mm<10) {
    mm='0'+mm
} 

var today = day+' '+yyyy+'-'+mm+'-'+dd+' ';
var selRange = editor.getSelectedRange();
editor.replaceTextInRange(selRange[0]+today.length,0,today);

if(min<10) {
    min='0'+min
}

if(sec<10 && hh<12) {
    sec='0'+sec+'a'
} else if(sec<10 && hh>=12) {
    sec='0'+sec+'p'
} else if(hh<12) {
    sec=sec+'a'
} else {
    sec=sec+'p'
}

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

if(hh<10) {
    hh='0'+hh
}

var time = hh+':'+min+':'+sec+'\n';
var selRange = editor.getSelectedRange();
editor.replaceTextInRange(selRange[0]+today.length,0,time);