Converting inline properties to frontmatter properties with a keypress in Obsidian
@readwithai - X - blog - Obsidian Cookbook -
I use properties as a form of typed link in Obsidian which I then use to create automated maps of content. This all works pretty well but the inline typed links can be a little ugly and detract from the flow of a note.
up:: [[Parent]]
You could instead add this as a property to the beginning of the note but this can require too much clicking for those used to being able to do everything with a keyboard.
This is the sort of problem well suited to my plugin Plugin REPL where you can use a dash of JavaScript to make your life easier.
If you execute the following snippet using Plugin REPL (after installing it) - by highlighting the code and running Plugin REPL: Execute the current line or selection
newCommand(function frontmatter_property(){
const [name, newValue] = lineAtPoint().split(/ *:: */)
if (!newValue) return
const old = view.metadataEditor.properties[name]
if (view.metadataEditor.properties.filter((x) => x.key === name).length === 0) {
view.metadataEditor .insertProperties({[name]: newValue})
} else if (Array.isArray(value)) {
view.metadataEditor.insertProperties({[name]: [...old, newValue]})
} else {
view.metadataEditor.insertProperties({[name]: [old, newValue]})
}
killLine()
})
You can then use the command Plugin REPL: frontmatter property to move an inline property to the frontmatter at the beginning of the file.
If you find this useful - you can run it every time Obsidian starts by adding it to your repl.md file.
I did this using my plugin Plugin REPL, but there are other ways to run JavaScript which you could use to adapt this script.
This is part of a cookbook of useful things you can do in Obsidian and with Plugin REPL (of which I am the author).
If you find this interesting and useful you might like to:
Read this page about how to make half-automated maps of content in Obsidian.
Read this somewhat academic review of note taking in Obsidian.
Look at some of the other Obsidian tricks.
You can also follow me on X or my blog.