How to add modified date to body of Draft?

Hi,
I’d like to add the modified date to the body of a Draft.
This is so I can then share the batch of Draft to Apple Notes and at least
have a record of the date the note/draft was last modified/created.

Ideally I’d like to do this on a selected list of Drafts, if not individually will do.

Any ideas?
Thanks!
D

A simple script snippet to add the modified date to the end of the text of a draft would look like:

// get the modified date
let dateStr = draft.processTemplate("[[modified]]");
draft.append(dateStr);
draft.update();

If you setup an action with that script in a script step, it could be run on the current draft, or used with selected drafts in the draft list using “Run Action” via operations on iOS, or the context menu on Mac.

2 Likes

Thanks for that, got that working! Is there a simple way to have the snippet
prefix the
draft.append(dateStr);
with some text like “Last modified:”

I tried using
editor.setSelectedText(“Modified date:”);
but it didn’t work when multiple drafts were selected.

Consider:

// get the modified date
let dateStr = “Last modified:” + draft.processTemplate("[[modified]]");
draft.append(dateStr);
draft.update();

This basically adds the label you want to the modified date from the draft to create the variable you want to append.

If that doesn’t point you in the right direction, post the code you’ve come up with so far.

2 Likes

Thanks for that, I get an error:-

Script Error: SyntaxError: Invalid character ‘\u201c’
Line number: 3, Column undefined

?

Some of the quotation marks were the wrong type (curly vs straight).

Try this:

let dateStr = "Last modified: "+ draft.processTemplate("[[modified]]");
draft.append(dateStr);
draft.update();
2 Likes

Thats done the trick! Thank you.

Thanks for the pickup! Not sure how those crept in…