Plugin to automatically replace text and move note?

I’ve got a note that looks like this:

---
tags: banana, 
---
type:: [[Fruit]]

I’d like to setup a command that does the following:

  1. Replaces the tag “banana” with “orange”. It will always be this replacement, it is not dynamic in any way.
  2. 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.

Any ideas on how I can set this up?

If you are on a mac, you could do that with the Hazel app which can always watch for files with particular attributes.

Thanks for your suggestion but am on Windows :slight_smile:

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

  );

};

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.