How to rename all notes in a folder, using the first header as the note name?

What I’m trying to do

I have a folder with over 12k notes in it. They have unhelpful titles like ‘D1650’ and ‘J1051’.

The name I really want for the note name is located in the first (H2) header within each note. E.g.

‘D1650 Other Characteristics Of Magic Objects’

or

‘J1051 Death’s Three Messengers’

Things I have tried

I started off using the primitive macro utility in Microsoft Keyboard and Mouse Center, manually placing the cursor at the beginning of the first header (but after the pound signs, e.g.

‘## [CURSOR HERE] D1650 Other Characteristics Of Magic Objects’ → run my macro

I worked at this for about 90 minutes before I realized it might have been faster to figure out how to do it with scripting.

Then I saw that the next folder I want to do has over 12k notes (can’t do it manually in a reasonable amount of time).


I saw the plugin Obsidian Filename Heading Sync, which does almost exactly what I want, only in reverse. I want to update the filename to match the first header, instead of the other way around.

I looked at doing it outside of Obsidian, but I would lose all the existing links.

i’m sorry but this is too niche a case for anyone to be bothered with it

also, this job is for outside of obsidian – even if it can be done with Templater somehow, i don’t anyone will be up for it

as for the links getting broken, you can update those as well

the new chatgpt4o (free) (down atm) can write you good python scripts if your prompt (your explanation of what needs to be done) is to the point

you can start out with 5-10 files in a test vault and notify the robot about the results (gone awry) and it will make the changes

over 4-5 tries, you will have got a working script you can use for the vault

it’s a tinkering job you will have to do alone

for posterity:

I found a plugin that seems to do exactly what I want: Auto Filename

So far it worked flawlessly on a test vault.

2 Likes

wow

thanks for writing that in!

handy plugin

Don’t be too eager on stating something like this, based on your own assumptions and after only a few hours.

It’s actually somewhat easy, if you know coding, since the headers are readily available in the metadataCache, and you’ve got proper rename tools accessible through various API’s. I.e. Templater.

Doing this through a python script though is a lot more work. I’m never going to advocate using AI to write it, but that aside you’ll need to handle all internal link renaming with that script, and that is not an easy task.

All in all, as the OP discovered there is already a plugin written for this task, so my advice in general is to try not to be too categoric/final/… in your answers, especially if you’re not very safe on the quality of your answer.

1 Like

this is coming too late, don’t you think?
it’s easy to act smart and wait for the rewards

i wrote something in to help – the pre-4o robot wrote elaborate python scripts for me that work

i also wrote in because some people will find it a challenge to prove me wrong – so in that I can take the blame and still help the person

this is a public forum or a private forum?

The question was posted just a few hours ago, and you jumped the gun with an answer which contained wrongful assumptions.

Knowing scripting by years of experience I doubt for that script to handle internal link renaming correctly in such a complex user space as Obsidian links are. So I doubt that script correctness unless loads of precautions has been taken.

Especially since this is a public forum I believe care should be taken not to present potentially hurtful/wrong advice, and be humble about us all being human with not knowing all aspects of the inner and outer working of Obsidian.

The other end don’t know what we know or not know, so they’ll easy take our advice to be the truth, even if it’s not even close to being so. So I try to be careful in that aspect, so as not to misuse this power.


I’m going to step away from this now, as the thread has been resolved with a good solution. And I’m not here for any reward, I just strongly believe in being open ended and allow for the community to speak and showcase various options to solving a request.

the old title will be used with a regex search – regex because we want to account for any aliases – to search the content of all files and updated with the new title in a loop – as I said, in 4-5 tries anyone will sort out the kinks and over time give themselves a chance to learn to be self-reliant…

…or should we all wait for the prospective de facto winners of digital king of the mountain contests?..

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