I’d like to setup a command that does the following:
Replaces the tag “banana” with “orange”. It will always be this replacement, it is not dynamic in any way.
Move the note to a folder based on the value in type (so in this case to /Fruit/). The type-value will be different depending on note.
I’ve found plugins to do both but neither can do it automatically. The “Regex replace”-plugin can replace the text but I can’t setup a command to prefill the values but have to do it myself everytime. The “Auto-move note” can move the note but can’t move it to a dynamic folder name.
I managed to get this sorted using Quickadd and Meta edit plugins. Here is the quickadd-script. It will move replace the tag “#future” with “#held” and then move the note to the folder named the same as the value found in “Project::”.
module.exports = async function moveFilesWithTag(params) {
const { app } = params;
// Get file
const activeFile = this.app.workspace.getActiveFile();
// Update meeting status
let tags = await app.plugins.plugins["metaedit"].api.getPropertyValue(
"tags",
activeFile
);
let udpatedTags = tags.replace("future", "held");
let outcome = await app.plugins.plugins["metaedit"].api.update(
"tags",
udpatedTags,
activeFile
);
// Get customer name and move to its folder
let customerLink = await app.plugins.plugins["metaedit"].api.getPropertyValue(
"Project",
activeFile
);
let pureCustomerName = customerLink.match(/\[\[(.*?)\]\]/)[1];
await app.fileManager.renameFile(
activeFile,
"🏙️ Customers/" + pureCustomerName + "/" + activeFile.name
);
};