Task Batch actions

Add condition where a task will get an inline tag once it's task score is set to high

Should be different from the first one, as both should be a true/false constants

@coding @Alta Energia



Create a function to delete a tag from multiple tasks in the current note/selection
@coding @next



Create a function to hide tasks from view



Create function in a plugin to transform all tasks in a note to bullet points
@coding @Media Energia



name

Task Batch actions

description

A plugin to batch task related actions inside a note

icon

check_circle

instructions

This is a plugin related to doing batch actions related to tasks. In the near future, I'll aim to add batch moving and completing tasks to this plugin in the future, but for now it only tags.

Select the text of a task, click on "Extract Selection" and select the inline tag you want to tag the tasks. This will automatically add the note tags to all selected tasks.


Entry: https://github.com/Matheus-Felipe-C/task-batch-actions/lib/compiled.js


linkUpdate History

May 8th, 2024

Internal update by adding a helper function, should not affect end users

May 7th, 2024

Added feature to move tasks between notes

Added support for Esbuild

March 21st, 2024

Updated function names to make them more readable

February 15th, 2024

Bugfix: function Batch tag tasks in the NoteOption now won't return an exception anymore

December 28th, 2023

Added function Batch tag tasks in the NoteOption.

November 30th, 2023

Bugfix: tasks now get tagged if they contain links inside the task title.

November 10th, 2023

First version out in the open


linkCode block

// Javascript updated 08/05/2024, 12:11:56 by Amplenote Plugin Builder from source code within "https://github.com/Matheus-Felipe-C/task-batch-actions/lib/compiled.js"
(() => {
// plugin.js
var plugin = {
replaceText: {
"Tag tasks in batch": async function(app, text) {
try {
await this._batchTagTasks(app, text);
} catch (err) {
console.log(err);
app.alert(err);
}
},
"Move tasks in batch": async function(app, text) {
try {
await this._batchMoveTasks(app, text);
} catch (error) {
console.log(error);
app.alert(error);
}
}
},
noteOption: {
"Tag tasks in batch": async function(app, noteUUID) {
try {
const taskNames = await this._transformTaskIntoText(app, noteUUID);
await this._batchTagTasks(app, taskNames);
} catch (err) {
console.log(err);
app.alert(err);
}
},
"Move tasks in batch": async function(app, noteUUID) {
try {
const taskNames = await this._transformTaskIntoText(app, noteUUID);
await this._batchMoveTasks(app, taskNames);
} catch (error) {
console.log(error);
app.alert(error);
}
}
},
async _batchTagTasks(app, text) {
const selectedTasks = text.split("\n");
console.log("All tasks to tag:\n");
console.log(selectedTasks);
const noteUUID = await app.context.noteUUID;
const noteTasks = await app.getNoteTasks({ uuid: noteUUID });
const systemNotes = await app.filterNotes();
const inlineTag = await app.prompt("Choose an inline tag", {
inputs: [
{ label: "Inline tag selection", type: "note", options: systemNotes }
]
});
console.log("Inline tag to add:\n");
console.log(inlineTag);
const tasksToTag = noteTasks.filter((task) => {
let taskContent = task.content.replace(/\\[\r\n]+/g, " ");
taskContent = taskContent.replace(/(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, "$1");
console.log("Task content without link:\n");
console.log(taskContent);
for (let i = 0; i < selectedTasks.length; i++) {
if (taskContent.includes(selectedTasks[i].trim())) {
return task;
}
}
return false;
});
console.log("Tasks to tag:\n");
console.log(tasksToTag);
await Promise.all(tasksToTag.map(async (task) => {
const newtaskName = ` ${task.content} [${inlineTag.name}](https://www.amplenote.com/notes/${inlineTag.uuid})`;
await app.updateTask(task.uuid, { content: newtaskName });
}));
console.log("Tasks tagged successfully!");
},
async _batchMoveTasks(app, text) {
const selectedTasks = text.split("\n");
console.log("All tasks to move:\n");
console.log(selectedTasks);
const currentNote = await app.context.noteUUID;
const systemNotes = await app.filterNotes();
const currentNoteTasks = await app.getNoteTasks({ uuid: currentNote });
const targetNote = await app.prompt("Choose a note", {
inputs: [
{ label: "Target note", type: "note", options: systemNotes }
]
});
console.log("Note to move tasks to: ");
console.log(targetNote.uuid);
const tasksToMove = currentNoteTasks.filter((task) => {
let taskContent = task.content.replace(/\\[\r\n]+/g, " ");
taskContent = taskContent.replace(/(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, "$1");
taskContent = taskContent.replace(/\\/g, "");
console.log("Task content without link:\n");
console.log(taskContent);
for (let i = 0; i < selectedTasks.length; i++) {
if (taskContent.includes(selectedTasks[i].trim())) {
return task;
}
}
return false;
});
console.log("Tasks found to move:");
console.log(tasksToMove);
await Promise.all(tasksToMove.map(async (task) => {
const noteUUID = targetNote.uuid;
await app.updateTask(task.uuid, { noteUUID });
console.log(task);
}));
},
async _transformTaskIntoText(app, noteUUID) {
const noteTasks = await app.getNoteTasks({ uuid: noteUUID });
const taskOptions = noteTasks.map((task) => ({
label: task.content,
type: "checkbox"
}));
const selectedTasks = await app.prompt("Select the tasks you want to act on", {
inputs: taskOptions
});
let taskNames = "";
for (let i = 0; i < selectedTasks.length; i++) {
if (!selectedTasks[i])
continue;
let count = i;
let rightTask = taskOptions.find((el) => {
if (count == 0)
return true;
count--;
});
if (rightTask && rightTask.label) {
let contentToAdd = rightTask.label;
contentToAdd = contentToAdd.replace(/\\[\r\n]+/g, " ");
contentToAdd = contentToAdd.replace(/(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, "$1");
taskNames += `${contentToAdd}
`;
console.log(contentToAdd);
}
}
taskNames = taskNames.trim();
return taskNames;
}
};
var plugin_default = plugin;
return plugin;
})()