Steps to reproduce
- Create two separate vaults.
- Open the first vault in Obsidian.
- Enable the Obsidian CLI.
- Outside of Obsidian, open a terminal and navigate to the second vault.
- Ensure that the second vault is not open in an Obsidian window.
- Execute the following:
obsidian eval code='app.appId'
Did you follow the troubleshooting guide? [Y/N]
Yes.
Expected result
My initial expectation was for the command to successfully execute in the context of the second vault without opening a visible window for the second vault . It should report the second vault’s id in the terminal.
After seeing the window open up automatically, my adjusted expectation was for the command to delay slightly until the new window was ready to execute the command successfully, but to still eventually report the vault id in the terminal.
Actual result
I received the following error message in the terminal the first time the command was executed, while the new window was still opening and loading.
Error: Command "eval" not found. It may require a plugin to be enabled.
Environment
SYSTEM INFO:
Obsidian version: 1.13.1
Installer version: 1.12.7
Operating system: #35~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 19:30:42 UTC 2 6.17.0-35-generic
Login status: logged in
Language: en
Catalyst license: insider
Insider build toggle: on
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: on
RECOMMENDATIONS:
none
Additional information
If you run the command a second time while the new window for the second vault is still open, everything works as expected.
Alternatively, navigating in the terminal to any path, even to the first vault’s path, and executing the following (filling in with the second vault’s actual id) produces the same result:
obsidian vault=<id> eval code='app.appId'
This appears to affect every CLI command I tried, even just obsidian version.
It appears that the code to run the CLI command does not wait for the second vault window to fully open and become responsive to commands. Instead it greedily attempts to run the command immediately after triggering the opening of the new window, but fails because the second vault’s run-time environment is not yet fully initialized and ready for commands.
My use case is that I’m trying to run app.fileManager.renameFile() from a plugin in my main vault in order to update files in a second vault and properly update links within that vault in reaction to the rename. The fact that it opens a window for the second vault is a nuisance, but I can live with that behavior for now. But to get around the CLI error, I am running a benign CLI command in a loop until it succeeds, and then I proceed to run the real CLI command that invokes renameFile(). It works, but it is janky.