Triggering an Obsidian command from within an event callback

My goal is to effectively execute the ‘navigateBack’ command from within the ‘file-open’ event listener in my plugin on certain files. The goal is to make it as if I had never triggered the load of that file at all (just for certain files.)

It would be great to be able to trigger an arbitrary obsidian command from within any callback function, still I will take any solutions no matter how hacky.

NOTE: This is my first plugin. I am so impressed that somehow you guys have written these complex plugins! There are no real docs it seems, it is all is just coding by grepping source code. I am very impressed!

Thanks for the help

SOLVED:

In line 11,776 of the QuickAdd plugin we see the ‘executeCommandById’ method:

   this.app.commands.executeCommandById('app:open-settings');

And this command does what one would expect… it runs the names command.
Wow, what a crazy way to code! I cannot wait for the plug-in API to be released…
(I didn’t find this method listed in any of the unofficial docs that I looked at)

6 Likes

It’s too bad to have no documentation. How can I get the ID of the command?

If you look at the post below, I showcase some ways of traversing the app.command.commands list of commands which holds the various ID’s. In the post I further exemplify how to get the hotkeys related to a command, which might not be useful in your case, @js2hou .

Here is another version traversing the same list (also by me :slight_smile: ):