Skip to content

Instantly share code, notes, and snippets.

@mattcassinelli
Created October 27, 2014 00:30
Show Gist options
  • Save mattcassinelli/37028a686952dbcd6f3e to your computer and use it in GitHub Desktop.
Save mattcassinelli/37028a686952dbcd6f3e to your computer and use it in GitHub Desktop.
Insert timestamp into Drafts
function getDateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
if(month.toString().length == 1) {
var month = '0'+month;
}
if(day.toString().length == 1) {
var day = '0'+day;
}
if(hour.toString().length == 1) {
var hour = '0'+hour;
}
if(minute.toString().length == 1) {
var minute = '0'+minute;
}
if(second.toString().length == 1) {
var second = '0'+second;
}
var dateTime = year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second;
return dateTime;
}
setSelectedText(getDateTime())
@mattcassinelli
Copy link
Author

Script written by Gabe Weatherhead on Macdrifter: http://www.macdrifter.com/2014/10/drafts-4-keyboard-scripts.html#fn:sort

Installation instructions:
To add this to the extra keyboard row in Drafts 4, do this:

  1. Click the pencil icon on the extra keyboard row to edit the keys
  2. Add a new key with the plus in the upper right corner
  3. Choose a "Script" type key
  4. Add the Javascript, label and voice over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment