Create environment variable for Java Script to use in DataView

how can I create environment variables based on a configuration file to access via the DV inline JavaScript code? I want to create links to files based on an environment variable, that I can set by hand. I use the following code, which works:

$= "[PDF](file://" +  process.env.HOME + "/Desktop/P1888.pdf)"

Basically, I want to set my own variable instead of HOME.

Are you planning to only use these “environment variables” inside Obsidian? If so, could you just have an Environment note with dataview fields and use them through dataview(js) as [[MyEnvironmentNote]].myField? That will avoid causing side-effects on your computer that might confuse other programs (like messing with environment variables that they want, or believe are empty).
If you’re using these environment variables somewhere else (e.g. a Python program), you could use that tool’s method for setting variables, which is probably right near the documentation you’d already be looking at for reading those variables.

Good luck!

Yeah, I plan to use them inside Obsidian. Instead of HOME, I want something like BASEPATH=/Users/Username/Seafile/, so I can make the location dependent on my Cloud storage path of the specific device I’m using. That should not cause any side effects.
Problematic is I don’t know how to define those variables to be readable by JavaScript inside Obsidian. For example with Python, I can just define them in my current shell, and when I run the script it knows those variables. This seems not to be the case for JS and Obsidian.

1 Like

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