Skip to content

Instantly share code, notes, and snippets.

@mygeekdaddy
Last active June 22, 2024 14:53
Show Gist options
  • Save mygeekdaddy/0330f57963529c93460c59fecb7b173f to your computer and use it in GitHub Desktop.
Save mygeekdaddy/0330f57963529c93460c59fecb7b173f to your computer and use it in GitHub Desktop.
Drafts app script to allow insert of current date in ISO 8601 format.
// See online documentation for examples
// https://docs.getdrafts.com/docs/actions/scripting
// Add keyboard shortcut Ctrl-Opt-D to insert date in current cursor location
var today = new Date();
var year = today.getFullYear();
var month = today.getMonth() + 1;
// need to +1 month since Jan = 00
var date = today.getDate();
dd = today.getDate()
if(dd<10) {
dd='0'+dd
}
mm = today.getMonth() + 1
if(mm<10) {
mm='0'+mm
}
yyyy = today.getFullYear()
var iso_date = yyyy + '-' + mm + '-' + dd ;
var selRange = editor.getSelectedRange();
editor.setSelectedText(iso_date);
editor.setSelectedRange(selRange[0]+iso_date.length, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment