Properties Wrangler: Add a way to "Insert", "Rename" and "Remove" properties and values in all files

Thank you Leifip.

Yes, the script you provided writes/replaces all files without testing if the property was used or not. (line “with open(file_path, ‘w’) as file:” and th next one)

I have used ChatGPT first to ensure it is possible to modify a file so out of Obsidian…
Its answer is yes :

es, Obsidian typically picks up changes made to the files within your vault, even if you make modifications manually outside of the Obsidian application. Obsidian relies on the file system to detect changes in your vault directory.

When you modify a file, including changing a property name, outside of Obsidian, the next time you launch Obsidian, it should recognize the changes and update its internal representation of the vault accordingly. Obsidian scans the files in your vault directory during startup and loads any new or modified files.

Then I’ve asked it to produce a python script modifying only the relevant files (not tested, I provided it as is)

(The correction point is in the added test “if updated_content != content:”)

import os
import re

def rename_property(file_path, old_property, new_property):
    with open(file_path, 'r', encoding='utf-8') as file:
        content = file.read()

    # Use a regular expression to find and replace the property name
    updated_content = re.sub(fr'(?<=^|\n){old_property}:', f'{new_property}:', content)

    # Check if the content was actually changed
    if updated_content != content:
        # Write the updated content back to the file
        with open(file_path, 'w', encoding='utf-8') as file:
            file.write(updated_content)

def rename_property_in_vault(vault_path, old_property, new_property):
    # Walk through all files in the vault
    for foldername, subfolders, filenames in os.walk(vault_path):
        for filename in filenames:
            if filename.endswith('.md'):  # Process only Markdown files
                file_path = os.path.join(foldername, filename)

                # Check if the property exists in the file before attempting to rename
                with open(file_path, 'r', encoding='utf-8') as file:
                    content = file.read()
                    if re.search(fr'(?<=^|\n){old_property}:', content):
                        rename_property(file_path, old_property, new_property)

if __name__ == "__main__":
    # Replace these values with your actual property names
    old_property_name = "old_property"
    new_property_name = "new_property"

    # Replace this with the path to your Obsidian vault
    obsidian_vault_path = "/path/to/your/obsidian/vault"

    # Rename the property in files that contain the property
    rename_property_in_vault(obsidian_vault_path, old_property_name, new_property_name)

Notice :

Adjust the old_property_name, new_property_name, and obsidian_vault_path variables as needed.

Please note that this script assumes that your properties are formatted as property_name: at the beginning of a line or after a newline character. If your property format is different, you may need to modify the regular expression accordingly. Also, always make a backup of your vault before running scripts that modify multiple files.

1 Like

+1 for me. This would be one of the best QOL features since Properties were created. lol

2 Likes

+1 big time for me!

I don’t even want to think about how much time I’ve spent renaming Properties as my use of the Properties feature evolves. Being able to rename and edit Properties across my entire vault would be SO helpful!!

2 Likes

+1 for me, definitely

I’ve wasted way to much time trying to rename properties in bulk, something like Tag Wrangler would be life changing.

2 Likes

+1. This would be a great addition to Obsidian.

2 Likes

Very good suggestion, I believe many people need these features

2 Likes

More generally I’d like to be able to

  • transform a inline field (type:: source) into a property (and conversely)
  • transform a tag in the note into a tag in tags property
    and because I added a folgezettel in all my note titles (ex: 10.b.3.f- my note), I’d like to move the folgezettel from the title into a property (and conversely) noting that the folgezettel (or any code) is followed by "- "(dash space) so easy to identify.
4 Likes

I am just getting started in setting up my properties and realized that this feature would be extremely useful.

@ryadaj @garryknight @leifjp
As a workaround, one can use bulk find and replace across folder[s] through Notepad++. It is pretty simple and built into Notepad++. This is how I used to rename tags before I found Tag Wrangler.

3 Likes

+1. This is desperately needed!

3 Likes

+1 Would be so helpful!

+1 I also support the idea as it could very time consuming to do it note by note !

Hey, you can check Basic editing > Search across files section of VS Code documentation to learn that, here is a direct link to it: Basic Editing in Visual Studio Code

+1, because it is essential.

Don’t forget something like undo/redo.

The user should have control about the changes: Which files add/change/delete which property?

4 Likes

Totally +1

1 Like

Rename (only) of properties types (not values) will be implemented in v1.5. No ETAs.

7 Likes

Legit! Thanks Obsidian team :yellow_heart:

2 Likes

@cvanhenten In case it is not on your radar, the update-time-on-edit-obsidian plugin may be helpful for future notes.
It automatically adds the created and updated properties.
The updated properties is updated each time you modify a note in Obsidian.

Is it present in the Catalyst version of v1.5?

@pellucid According to what I can read in v1.5.0 Release Notes, Properties can be renamed and searched globally.

See here for a demo video in the Catalyst

The plugin “Multi Properties” (GitHub - fez-github/obsidian-multi-properties: Plugin for Obsidian that allows user to add properties to multiple notes at once.) is related, allowing for Properties removal.

3 Likes