Book Search: Replacing Colons in Book Titles

Hello! I would appreciate any help with this. I have some coding knowledge but it’s pretty basic and surface level and I think this is beyond me.


What I’m Trying to Do

I am using the Book Search plugin to find and keep track of books I am reading and compile my thoughts/notes. The problem I am experiencing is that quite a number of the books I read have titles containing colons, which is not allowed in file titles.

The plugin and/or obsidian fixes this by just getting rid of the colon in the file’s title, but these book titles can be long enough that I would want some sort of separation. I would just go in and add dashes where the colons previously were myself, but this can be tedious and I want to automate it a bit.

Things I Have Tried

I have tested using the Templater command ‘<% await tp.file.rename(tp.file.title) %>’ as part of the inline text of the note in the template for the new books and tried adding extra text, (tp.file.title + " 2"), just to see if it works, and it does but this would probably only work by adding text at the beginning or end of the title. Plus, it would happen for every single book I add.

I have tested changing the new file name format in the book search plugin settings from {{title}} to {{title}} - {{subtitle}}, but the problem is that this only works when the book’s subtitle is classified as a subtitle in Google Books’ API/Google Books (what the plugin uses to find books), and quite a few of the books I want to use don’t have the part past the colon as a subtitle and it is instead just a part of the title.

I tried adding quotes around {{title}} in the plugin settings but it seems the plugin itself gets rid of any colons in the title ahead of time because it does not appear in the title either way.


Honestly, the more I think on it, the more I think it may just be futile and I should just go in and manually change the file titles to add the dash where it needs to be. But if anyone has any other suggestions, I’m open to them.

1 Like

Hi.

Not what you want, but my workaround for this is to leave the recast file names as they are but to capture the correct titles as aliases in the YAML header:

aliases: "[[{{title}}]]"

If I want to create a regular link to a book, I use the alias version; and when I use Dataview to query books in my vault, I also use the alias value from the YAML header.

Hope / expect that someone else will have a smarter idea.

This is not a suggestion on how to do the search and replace, but in regards to the colon character itself - I use this one:

It looks just like a colon, but it’s a completely different character (the “modifier letter colon”) and it’s safe to use in Obsidian titles and filenames :slight_smile:

Here’s a colon : and here’s the other one ꞉

2 Likes

The developer, @anpigon, wrote code to replace illegal characters in file names, including colons.

SEE: Cannot create title with question mark in it

Perhaps it would be possible to submit a request for the replacements to be configurable or for the default for colons to be something like space en dash space.