Is using `app.commands.executeCommandById` officially supported?

I’m working on an Obsidian plugin that needs to use commands from other plugins. For example, one of the things I would like it to do is to run “Open today’s daily note” command.

I am currently using the following:

this.app.commands.executeCommandById("daily-notes");

However, I wonder if this is the correct, official way to do this. I suspect not, because:

  • There’s no mention of the command attribute under App in the official docs
  • I saw someone mention this being deprecated (in this post)
  • I’m getting a TypeScript build failure Property 'commands' does not exist on type 'App'

Is there an officially supported way to run commands from other (core or community) plugins?

1 Like

I was thinking the same thing.

I believe that avoiding compile errors compromises the safety of type definitions. I usually check for the existence of a command before executing it like this, but I would like to know the official way to do it.

const commandId = "ID";
const commands = (this.app as any).commands;
const commandExist = commands.listCommands().some((cmd: any) => cmd.id === commandId);
commands.executeCommandById("ID");