Bulk update metadata in front matter YAML

Is there a way, to bulk update the front matter metadata from multiple notes? I have either a list of notes or some search criteria (like tags or keywords) where I want to change the metadata.

Things I have tried

  • Replacing single tags like “#foo with #bar” using grep and sed
  • Renaming fields with grep and sed

What I’m trying to do

  • Add tags
  • Remove specific tags
  • Add a field
  • Update field to a specific value
  • Update field with current time
1 Like

The Tag Wrangler plugin can rename the tags. It can’t remove them, but if you don’t mind a little hackiness you could rename tags you want to delete to something like “deletedtag”.

Note (because of your example) that you need to leave off the “#” when putting tags in the front matter, because that symbol marks comments in YAML.

I don’t know of a way to bulk change the other fields, but there might be a plugin.

If you can use python : py-obsidianmd is a python library that enables you to do just that, in a couple of lines of code.

You can check out the presentation video, github repository or examples.

In your case, you’d do something like this:


from pyomd import Notes
from pathlib import Path
from pyomd.metadata import MetadataType

paths = Path('/path/to/directory/containing/notes/')

# create a notes object
notes = Notes(paths)

# perform additions / removals of metadata
notes.metadata.add(k="meta_key_to_change", l=["new_val1", "new_val2"], meta_type=MetadataType.FRONTMATTER)
notes.metadata.remove(k="meta_key_to_change", l=["remove_val1", "remove_val2"], meta_type=MetadataType.FRONTMATTER)

# update your notes
notes.update_content()
notes.write()

Be careful to backup your vault before trying this. Batch modifications are always a bit risky.

1 Like

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