Action
HashTagged lines to Drafts
This script will 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 use this managing project reference files. Create a bunch of project files, and make sure the name of the project is the first line of the draft. Then add a hashtag to some lines, like “#week” for tasks you want to get done this week. Then this script will create a new draft with just those project names and lines.
Steps
-
script
// Get hashtagged tasks from all projects // Global variables. // Set the "tag" to whatever hash tag you want to use let tag = "#week"; 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("archive"); // 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 #week 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 #week 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("projects"); c.isFlagged = false; c.isArchived = false; c.update();
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.