I am trying to add a tag to muliple notes that all have the same property.
Example: For all the notes with the property “status” and the value “1” I want to add the tag “high”.
Things I have tried
I searched up in the help docs and forum:
bulk edit
meta data edit
add tag
property edit
I have tried
I have tried tag wrangler, but thats only to change tags.
I have tried vscode, but thats only for search an replace, not add.
I have tried the plugin db folder, but that didnt added any tags to mulitple notes at once
The closest I have been was with a unpopular plugin called “Multi Tag”. I was able to add one tag to muliple notes that are in the same folder. It would be helpful to know how to add multiple notes with the same specific property to one folder at once, but I guess thats the next rabbit hole.
So my question ist: How can I add one tag to muliple notes, that all have the same specific property, at once?
Hehe… the example was just that, ang example. You need to properly type out what your replacement should be, but it will work with the correct replacement string.
However, for it to work with Tags it do depend on the order of properties and so on. If that’s not a given, you might be better off doing a dataviewjs (or another script variant), where you for the files to be changed, and then call processFrontMatter() (if it’s named that still) to add your custom tag.
Just downloaded it, make.md looks like a good step in the right direction. However, I only have managed to create spaces. I wasent able to add one tag to mulitple notes at once. Is there a trick to it?
okay, I got it. It works with “make.md”. Thanks a lot!
Solution
I installed the plug in “make.md” und searched in the search bar of “make.md” für the property I needed. I marked all the files, draged on droped them into a folder. And with the plug in “Multi Tag” I was able to just add the tag with one click.
Hello, you can also attain the desired outcome using a Python script, which reduces security risks compared to installing additional plugins. To each their own.
Before you begin, it’s wise to create a backup of your vault. Ensure you set the directory to your vault or the folder you’re working with.
import os
# Function to check if the status is 1 and add 'high' to tags if it is not present.
def process_header(lines):
# Flags to check if the 'property: status' and 'value: "1"' are present
has_status = False
value_is_one = False
tags_index = -1
# Iterate over the lines to check the flags and find the index of tags
for i, line in enumerate(lines):
if line.strip() == 'property: status':
has_status = True
elif has_status and line.strip() == 'value: "1"':
value_is_one = True
elif line.strip().startswith('tags:'):
tags_index = i
# Check if 'high' is already in tags
if 'high' in line:
return False # No need to process further if 'high' is already a tag
# If the status is 1, add 'high' to the tags
if has_status and value_is_one and tags_index >= 0:
if '[]' in lines[tags_index]: # Handle empty tag list
lines[tags_index] = lines[tags_index].replace('[]', '[high]')
else:
lines[tags_index] = lines[tags_index].rstrip() + '\n - high\n'
return True
return False
# Function to process each markdown file
def process_markdown_file(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
# Find the start and end of the header
header_start = -1
header_end = -1
for i, line in enumerate(lines):
if line.strip() == '---':
if header_start < 0:
header_start = i
else:
header_end = i
break
if header_start >= 0 and header_end > header_start:
header_lines = lines[header_start+1:header_end]
if process_header(header_lines):
lines[header_start+1:header_end] = header_lines
with open(file_path, 'w', encoding='utf-8') as file:
file.writelines(lines)
print(f'Updated {file_path}')
# Function to traverse the folder and process all markdown files
def process_folder(folder_path):
for root, dirs, files in os.walk(folder_path):
for filename in files:
if filename.endswith('.md'):
file_path = os.path.join(root, filename)
process_markdown_file(file_path)
# Replace 'your_folder_path_here' with the path to the folder you want to process
folder_path = 'your_folder_path_here'
process_folder(folder_path)