Node.js not on mobile : How to use Obsidian API in Quickadd user script?

In a user script for @Christian’s Quickadd, I used node.js fs and path to read/write data using a normalized path (for better cross-platform).

However, it seems we can’t use node.js on mobile. Instead, I should probably use write, read and normalizePath from Obsidian API, so that it will work on both desktop and mobile.

In a quickadd user script, we get a reference to Obsidian’s app, but from that how could I use write, read and normalizePath ?

app.write, etc… leads to is not a function error, and

obs = require('obsidian')
[...]
path = obs.normalizePath(...)

also leads to normalizePath is not defined.

Those functions are part of the Vault class: https://marcus.se.net/obsidian-plugin-docs/api/classes/Vault

you should be able to access them using obsidian.vault.

normalizePath is not part of the Vault API and can be imported separately.

1 Like

Thanks @joethei !

For normalizePath access in a Quickadd’s user script, please refer to this.

1 Like