Script to create a new entry with timestamp in a draft made of successive entries

This is a more complex script than the previous ones I posted here ; this time, I include a timestamp in the new entry (YYYY-MM-DD-day hh:mm). By default, the timestamps are sorted by date and time (i.e. in the last entry, it’s the current date and time, but if you insert an entry between two existing one, it’s the date and time of the following one).

As a reminder, I use Drafts in a single draft that I divide between “entries” during the day when I write notes, in order (i) to separate notes at each time of the day but also (ii) to have daily notes into the same draft so that I can scroll them, annotate them, create actions on them (with Drafts actions) and have a global vision on the same page. Later on, I export the entries in another app (I’ll explain later how I do that).

The script is in the Directory.