Things I have tried
Hi, I try to create a QuickAdd macro which will run a js script.
In the js script, I want to create a canvas file and move it to the specific directory rather than the default one.
The js script code is as following:
// step1. create the canvas file with execute the command
await app.commands.executeCommandById('canvas:new-file');
// step2. get the created file info
// ERROR: `console.log( app.workspace.activeLeaf.view.file)` print the file as null
debug(app.workspace.activeLeaf.view.file);
let canvasFilePath = app.workspace.activeLeaf.view.file.path;
// step3. rename the file for moving it to the target directory
let tFile = app.vault.getAbstractFileByPath(canvasFilePath);
app.vault.adapter.rename(tFile, targetDir);
What I’m trying to do
As the comment shows in the code before, when I run the js script with QuickAdd command, the workspace.activeLeaf.view.file
is undefined.
But when I tried it in obsidian console, it seems ok. I don’t know why or what did I missing.