You are right. I wonder how I could miss that. I remembered I had checked it as well. I even searched for the whole computer. Anyway, I wonder why it decides that the current location is the main vault, not in the plugin directory, where the js file locates?
I see. So app is also a class as well. Reading the documentation I don’t see much explanation of it. Can you explain how it works?
Yes the content of that variable is displayed in the console, but I cannot call it again directly in it. Both jsonContent and this.app.plugins.plugins.dotmaker.jsonContent do not work.
I want to automatically update the output every time the plugin runs. create cannot overwrite the file, so I guess modify is the way to go. But I get:
Uncaught (in promise) TypeError: Cannot create property ‘saving’ on string ‘output.json’
The App class represents the currenlty running instance of obsidian.
This is because your jsonContent variable is only accesible inside your onload() function, to be able to read it you need to change its scope(see the link in my last reply).
The modify function requires the use of a TFile, you can get
this by using the getAbstractFileByPath function and the checking if the returned value is instanceof TFile.
If this is not the case you should create the file.
One thing I do notice is that you do not use TypeScript(which is the default for obsidian) to write your plugin, it should not even allowed you to compile the plugin.
Here is a short tutorial to get you started:
However, it’s interesting that when I use the path "/", I get a circular object:
VM314:1 Uncaught TypeError: Converting circular structure to JSON
--> starting at object with constructor 'e'
| property '_' -> object with constructor 'Object'
| property 'rename' -> object with constructor 'Array'
| index 0 -> object with constructor 'Object'
--- property 'e' closes the circle
at JSON.stringify (<anonymous>)
Add a console.log('captures/' + getFileName()) just to make sure your file name is correct. When I had this problem it turned out that I had a problem with the file path/name and node just wasn’t throwing me an error to explain.
Hmm, I use getAbstractFileByPath for a file that is outside the vault and a file inside that vault, and both are not contained in a hidden folder, and it’s still null.
Here is how this works:
Relative path for existing file inside .obsidian
const configPath = this.app.vault.configDir + "/plugins/dotmaker/data.json";
[[PromiseResult]]: "TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
Absolute path for existing file inside .obsidian
fileinside = app.vault.adapter.basePath + "\\.obsidian\\plugins\\dotmaker\\data.json";
[[PromiseResult]]: Error: "ENOENT: no such file or directory, open 'D:\Quả Cầu\B Nội dung\Knowledge graphs\Cây vấn đề\D:\Quả Cầu\B Nội dung\Knowledge graphs\Cây vấn đề\.obsidian\plugins\dotmaker\data.json'"
[[PromiseResult]]: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
For the file with absolute path outside .obsidian but inside vault, the error is the same with the file inside .obsidian.
checking the properties of app.vault.adapter I see a writeFile() fsPromise, with the arguments like this:
I try app.vault.adapter.writeFile(configPath, output) and it doesn’t work, but the autocomplete suggests me to try app.vault.adapter.write(configPath, output). This time it works. I have no idea how to get to understand solution though