Basic script to insert a simple timestamp

The timestamp format is simply ‘hh:mm’ and is inserted right at the cursor location.

The script is in the Directory.

Hello, how can I alter the script so the cursor has a space after the timestamp?

Many thanks!

The easiest way if you are not comfortable with JavaScript is to just add in an Insert Text action step and have it insert the space after the time has been inserted. The cursor is then placed after the space.

1 Like

Thanks for your help!


indeed, the Insert Text action is easier.

Just for fun, here is the script with your request:

let loc = editor.getSelectedRange()[0],
  now = new Date().toTimeString().slice(0, 5);
editor.setTextInRange(loc, 0, now + ' ');
editor.setSelectedRange(loc + 6, 0);

You could also just use the following text in an Insert Text action to go the opposite direction and do it in one line no scripting (thanks to Drafts’ template engine). :wink: