Tag Mass Action: Add, Rename, and Delete a tag in multiple files (Tag Wrangler)

Also sending my thanks for this plugin :pray:

I really should have read the whole thread first to see the better solutions that had already been posted. But I wrote this bash script for my own use, and I might as well dump it here:

#!/bin/bash
set -e
FROM="#context-home"
TO="#home"

# Search for all .md or .MD files in the current working directory.
# For each, do the indicated replacement.
find . -type f -name "*.md" -o -name "*.MD" | while read file; do
    # If the file does not contain the FROM string, skip it.
    grep -q "$FROM" "$file" || continue
    echo "Processing $file"
    sed -i "s/$FROM/$TO/g" "$file"
done

(I should say, really, ā€œGithub Copilot and I wroteā€. My bash/find/sed ability is weak enough that it would have taken me a good half an hour to look up the right usages on my own. AI, man.)

1 Like

Iā€™ve been searching for a solution to this, and wanted to share mine! Canā€™t believe I didnā€™t think of this before. My goal was simple: delete the tag literature from my vault. The wonderful Tag Wrangler plugin doesnā€™t support deletion, but it does support renaming.

First, I renamed the literature tag to a random string (letā€™s say OmGsQgSzTw, generated here). After, I opened my vault in VSCode and used their find and replace to replace all occurences of OmGsQgSzTw with nothing. However, tags can come in a few formats, and just removing the string might not work. For instance, I replaced the strings (everything in quotes, including commas): " OmGsQgSzTw," & ā€œ, OmGsQgSzTwā€ & ā€œ#OmGsQgSzTwā€. That did the trick!

In hindsight, unbelieveably obvious. I was trying to regex and script my way through it, but this is significantly easier. Just wanted to drop this for anyone else also looking for tag deletion! Of course, make backups of your vault or labelled git commits just in case, but I didnā€™t run into any problems. Depending on the number of notes you have, the renaming, find and replace, and re-indexing can take a little while.

1 Like

+1 for tag rename, delete, organize feature

2 Likes

Tag Wrangler works for me, but still +1ā€™ing for this to be a core feature :wink:

7 Likes

Iā€™m suprised that nobody mentioned the ā€œGlobal Search and Replace Pluginā€ yet. I just deleted a tag successfully using it. For renaming tags, I use TagWrangler.

1 Like

Is there a way to assign the same tag(s) to multiple notes at once?

MOD-EDIT:
Related To: Tag Mass Action: Add, Rename, and Delete a tag in multiple files (Tag Wrangler)

83 Likes

Other than one by one? I donā€™t think so, except really ugly hacks with external scripts

2 Likes

Yes, I meant ā€œbatch addingā€ of a single tag to multiple files.

ie: You have Ford, Fiat, Chrysler, VW, Audiā€¦ etc files and you want to tag them all with #carbrand

3 Likes

I didnā€™t realize something like this was not possible.

3 Likes

How is the list of files going to be specified?

  • Selection of files in file Explorer within Obsidian?
  • Files refered by collection of links within some markdown file?
  • All files contained in folder and its subfolders?

Edit thanks WahWah for clarificationā†“.

  • list copied from search results
3 Likes

Like in most apps where this is any easy thing: search across all notes for a subset you want to tag. Use REGEX to get said set, select all results. Use the tag option to tag all entries in the set. Done.

3 Likes

From https://forum.obsidian.md/t/obsidian-release-v0-9-3/6622

When using global search, you can now copy the search results file list. This can be optionally formatted as wikilinks and/or as lists.

Now it is available as last icon above search text box. I do not know if API version of this command exists.

I think this request could be best done as a plugin.
I do not know if it is better then to store it in feature-requests or plugin-ideas category.

The plugin could:

  • add custom hotkeys for even faster use. Especially when Single key hotkeys (context sensitive) become supported.
  • have options whether to add tags:
    • to standard front-matter field ā€œtagsā€
    • in some other syntax/place
  • have option to insert only those tags that are not assigned yet to given note
    • in YAML front-matter field ā€œtagsā€
    • in some other syntax/place
2 Likes

Since tag support is already a core feature of Obsidian, I would argue this feature request is best implemented as a core feature. As @WahWah said, this is pretty standard in apps that support tagging.

As to the specific UI implementation, @malecjan mentions several good options. As with other file management actions, I think it makes sense to let the user do it in several different ways. Using the File Explorer and Search Results seem to be the most compatible with Obsidianā€™s current UX.

File Explorer

First, multi-select of files in File Explorer, then
ā†’ right-click menu ā€œAdd tag to selected filesā€
ā†’ command palette ā€œAdd tag to selected filesā€
ā†’ drag selected files to the tag in the tag pane OR drag the tag from tag pane to the selected files

Search Results

First, perform a search query that give results, then
ā†’ click a new # button (next to the ā€˜copy search resultsā€™ button) to assign a tag to all notes in the search results

26 Likes

Iā€™m all about this feature. Iā€™d just like to add that there also needs to be a way to REMOVE a tag. So if there is a context menu or command palette item for ā€œAdd a tag to selected filesā€, there should also be one for ā€œRemove a tag from selected filesā€.

11 Likes

@Gem, this may help:

By the way, an example of free software that can mass search and replace is VSCode.

Thanks

2 Likes

We need an interface that can manage labels systematically, and more abundant label functions.

1 Like

Thank you but Iā€™m not talking about editing or removing a tag at the global level. I meant removing a tag from, say, 5 selected files out of 100 that have that tag. Really just the inverse of adding a tag to multiple selected files.

4 Likes

+1 on the feature request for being able to add or delete tags in batch mode.

1 Like

+1 Would love support for this too!