Action
combine drafts from workspace
created by @FlohGro / more on my Blog
combine drafts from workspace
this action combines drafts from a workspace into a single draft.
This action was inspired by this post in the Drafts Forum.
The resulting draft will contain the content of all drafts in a bullet list with the creation time as a prefix:
# Drafts from 2022-03-15
- 08:00: some content of a draft
- 08:30: maybe some other draft which was dictated
- 09:01: and another draft
[Configuration]
- edit the script step of this action and change the variable
workspaceName
to the name of the workspace you want to use this action with - if you want change the variable
draftTitle
to change the title of the resulting draft
[Usage]
The use case in the forums post was to combine all drafts from a workspace e.g. today into a single draft.
If you find this useful and want to support me you can
Steps
-
script
// combine drafts from workspace const workspaceName = "Today" const draftTitle = "# Drafts from " + draft.processTemplate("[[date]]") // find workspace let workspace = Workspace.find(workspaceName); // query the workspace in this example the "all" tab for all drafts let draftsToProcess = workspace.query("all"); // now all the drafts from that workspace are in the array of drafts: draftsToProcess // create a new Draft: let destinationDraft = new Draft(); destinationDraft.content = draftTitle + "\n\n" for (curDraft of draftsToProcess) { let creationDateStr = createTimestampFromDate(curDraft.createdAt) let lineStr = "- " + creationDateStr + ": " + curDraft.content destinationDraft.content = destinationDraft.content + "\n" + lineStr } destinationDraft.update(); function createTimestampFromDate(date) { let hours = date.getHours() let hoursStr = "" if (hours < 10) { hoursStr = "0" + hours } else { hoursStr = hours } let minutesStr = "" let minutes = date.getMinutes() if (minutes < 10) { minutesStr = "0" + minutes } else { minutesStr = minutes } let returnstr = hoursStr + ":" + minutesStr return returnstr }
Options
-
After Success Default Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.