I found this extremely useful script that search a specific workspace for drafts, then pull each line tagged with a hashtag and append it to a new draft, along with the title of the draft where the line came from.
I have been trying to modify it to allow for the action to append to the current draft rather than creating a new draft, however, no success.
Was hopping that someone smart can help
This is the script
// Get hashtagged tasks from all projects
// Global variables.
// Set the "tag" to whatever hash tag you want to use
let tag = "#nextaction";
let date = Date.today().getWeek();
let n = "";
// find all drafts in the "Projects" workspace archive. Set your workspace and query accordingly (you might want drafts in the inbox, or all, or whatever)
let ws = Workspace.find("Projects");
let dList = ws.query("flagged");
// Loop through each draft
for (let z in dList)
{
// Split drafts into lines
let d = dList[z].content;
let lines = d.split("\n");
var t = "";
var bool = false;
var q = "";
// Look for #nextaction tag in each line
for (let line of lines)
{
// Grab the project name from the title of the Draft
t = dList[z].processTemplate("[[title]]") + "\n\n";
// If the line includes the #nextaction tag, set the bool to true and write the task to the q variable
if (line.includes(tag))
{
q += line + " [link](" + dList[z].permalink + ")\n";
bool = true;
}
}
// If the bool is set to true, write the project name and all tasks to the n variable
if (bool == true)
{
n+= t + q + "\n";
}
}
let c = Draft.create();
c.content = "# Tasks for Week " + date + "\n\n" + n;
// Set whatever tag / flag values you want here for the draft
c.addTag("project");
c.isFlagged = false;
c.isArchived = false;
c.update();
Author @derekvan