Is there an action that collect together all the drafts written at the end pf the day and put them together in a new draft?
Is the inbuilt option sufficient, or do you require greater automation. It would be quite straight forward to put together if you did, and would be a good first exercise if you have not created scripted actions before.
Thanks
the first automation needed is to collect by “today”… where should I look to create a SIMPLE script?
Well, just to be clear, I said straight forward, not “SIMPLE”; simple would be the least effort, which for me would be the built in merge function referenced above.
In terms of a bit of guidance, here is one approach you could take to tackling this.
You can use a temporary workspace to get today’s drafts.
https://scripting.getdrafts.com/classes/workspace
You can then “query” for a list (array) of Drafts in the workspace inbox.
For each draft in that list/array, you take it’s content property, join them together separated by whatever text you wish (e.g., a newline) and put them into a new draft.
https://scripting.getdrafts.com/classes/draft
If you wish you could then automatically do something else with the new draft, such as load it into the editor.
https://scripting.getdrafts.com/classes/editor
Hope that helps.
I had a few minutes to spare this evening, so I put together a commented example, and dropped it into an action.
Reveal the Example Code
function mergeDraftsToday(p_Separator = "\n")
{
// Create a new workspace object
// We are not going to save this, just use it to get today's drafts
let wsToday = Workspace.create();
// Build a query date for drafts created today
let qdStart = new QueryDate();
qdStart.field = "created";
qdStart.type = "absolute";
qdStart.date = Date.today();
// Assign the query date to the workspace
wsToday.startDate = qdStart;
// Get an array of drafts from the inbox for the 'today' workspace
let adToday = wsToday.query("inbox");
// Create an empty array and populate it with the content of today's drafts
// Each draft's content becomes a separate element in the array
let astrOutput = [];
adToday.map(dToday => astrOutput.push(dToday.content));
// Create a new draft from the array of draft content
// The drafts are concatenatd using a separator string passed into the function
let dNew = Draft.create();
dNew.content = astrOutput.join(p_Separator);
dNew.update();
// Load the new draft and activate the editor
editor.load(dNew);
editor.activate();
}
// Merge today's drafts into a new draft with two newline characters between each of the drafts' content
mergeDraftsToday("\n\n");
Thanks a lot, I’ll study it!
thanks again, but…
is there any possibility to append (or prepend) instead of simply adding? So to avoid duplicates when the action is invoked more than once?
Yes, you could definitely do that.
You would need to track what you have already processed to avoid duplication. You could do that with a tag or by use of archive.
You would also need a way to uniquely identify today’s merge draft. Then you could use that to append/prepend into, and also exclude it from today’s drafts. Maybe a unique title format or a tag combined with today’s date would be sufficient to identify it.
But, you could also come at it a different way. You could regenerate the draft. Have the action delete any existing merged draft to begin with, then when you generate the merge, you’ll be doing it as if for the first time.
Hope that helps.