In CustomJS, how can I use functions like normalizePath() in a script?

normalizePath() is an Obsidian API function, and it requires writing import { normalizePath } from 'obsidian'; first. That doesn’t work in a script (or at least an invocable one.) I looked at but I couldn’t figure out how else to add it.

I’m not sure if this is you asking the same question in a different forum but the link below talks about one option, using a trick to get access to the obsidian object from some plugin which exposes it, like the tp.obsidian from the Templater plugin or params.obsidian by other means within the QuickAdd plugin. Not sure if the CustomJS or Dataview exposes this by default.

This could possibly be done from within CustomJS using something like:

const tp = app.plugins.plugins['templater-obsidian'].templater.current_functions_object
tp.obsidian.normalizePath( ... )

Note that for the current_functions_object to have a value, it’s a requirement that some Templater code has been run since the last time Obsidian was started. This could be easily remedied, if it’s an issue in your case, by using an empty startup template within Templater setup.

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