I searched and couldn’t find anything that does this. Does anyone know of anything that does or if it would be expected that a plugin can access the functionality to do this?
As a user of Obsidian,
I want the software to automatically create an alias or sanitized version of a note title when I attempt to name a file with special characters that are problematic for filesystems (like question marks, slashes, or colons),
So that I can name my notes in a way that is meaningful and useful for my later understanding and retrieval without worrying about compatibility or technical restrictions.
Here’s a basic guide tested on my computer:
- Create a template note called “Creation Template” (this will be used by Templater on each new file creation to sanitize the name)
- Install Templater, and make sure to check the “Trigger Templater on new file creation” option in the plugin’s settings
- Lower on the plugin’s settings check the “Enable Folder Templates” option, then click the “+” button and in the below fields make sure the folder is set to “/” to intercept new file creation in any location of the vault, and in the template field choose the “Creation Template” you created earlier
- Close the settings page and type the following code in the Creation Template you created earlier:
// ask the user for the new note's filename
// and remember old title to turn it into an alias
let title = await tp.system.prompt("Enter file name:");
let old_title = title;
// replace illegal OS characters
title = title.replace(/[:?\/<>"\|\*\\-]/gi, " ").trim();
// find out in which folder the note is being created
// and compute the full path to the new note
let folder = await tp.file.folder(true);
let path = folder.replace(/\/?$/, '/') + title + ".md";
// if the note doesn't exist, create it
// otherwise warn the user in the new note's content
if (!(await tp.file.exists(path)))
tR += "File already exists!\n"
aliases: <% old_title %>
And that’s it, go anywhere in your vault, click the New Note button and Templater will ask you the file name, stripping any invalid characters before creating it and replacing them with a whitespace (if the sanitized file name already exists, the new note won’t be renamed and instead an error will be inserted in the new note)
P.S. I know, it’s far from perfect but it gets the message across.
[edit: I added the invalid title as an alias as I had forgotten about that part of your request]
I’ll give that a shot. Will or can it work if I create a new note from the quicklauncher or via a link that doesn’t exist ?
It works just fine from the quick launcher, but if you try to create it via a non-existent link reference it will not work because apparently Obsidian does a file name check before creating a note via a link.