Things I have tried
My current setup involves this templater code in the readwise highlights section:
and this script in the
scripts folder of my Obsidian vault:
In theory… this should work.
app.vault.read the file after I
app.vault.modify it to remove the tabs… I can see that the tabs are removed (see bottom left part of each
(Note: I don’t think the
TypeError from Meta Edit is relevant here.)
Yet, when I look at the file after templater has ran (and I know it has because the templater code is gone from the note), I see that the tabs are still there:
So, I’m stuck. Any ideas?
What I’m trying to do
Hey everyone. I noticed that the Note Refactor plugin doesn’t work when there are tabs. Demo:
So, I want to remove all tabs in this note.
Except… this note was created automatically by readwise as an import.
I don’t want to have to do this for every note readwise imports.
Hence, I want to leverage templater to do it automatically when readwise imports the note, for each note readwise imports.
I’ve not seen too much on the rest of your script, but I would rather use “\t” to match tabs, then an actual tab inserted into the string.
And shouldn’t you
await the modifying of the file also? And check for error result of the various calls (if they give them).
- re: using
\t for tabs, I was actually using 4 spaces as the string. I tried using
t.replaceAll("\t", "");) and it didn’t do anything:
await before file modification, that makes sense. Will try that. I haven’t seen many examples use
await - I wonder why they don’t? Anyway, here’s a rerun with
await and using
replaceAll(". ", "") as I had before:
Same thing as before: it shows that the tabs were replaced in the
console.log, but the note itself in obsidian shows no tab replacement:
- re: error result. There are none related to this specifically, that I can tell. The
TypeError after the
console.log I believe is from Meta Edit and is unrelated.
Does that mean you’re running the script from within the file itself?
If that’s the case, that could be your issue as well. Then that would need to be kept in memory, whilst you then reread and change the file. If nothing else that does sound like you’ve got some unhealthy race conditions going on.
A few hours back I prepared a script to change the frontmatter of multiple files, and I’m wondering whether something similar could be used in your case. But I would never run that (or similar) script from within the note itself. To me that sounds like sawing off the branch you’re sitting on.
It’s not obvious to me where it’s running from. I assumed it wasn’t running from within the file, rather from within Obsidian.
Oooh, I would be interested in this script!