Please allow me to execute commands by name in CLI without requiring ID

Use case or problem

The new CLI is AWESOME!!!

However, one small improvement please? Currently you must use the command ID with the CLI method

obsidian command id="thing"

I’m not sure what the reason is for this choice. Is it possible to have commands with colliding names?

Anyhow, for things like QuickAdd this is not so easy to deal with. see [[#Current workaround]] below

Proposed solution

  • If possible, allow a name argument to the command
obsidian command name="command name" 
  • Otherwise make the output of obsidian command show names AND ids in its output.
  • Or create an alternative search option that does, something like this but with perhaps better/cleaner syntax.
obsidian command names

Current workaround

Currently what I do is

obsidian eval code='app.commands.listCommands().filter(c => c.name.includes("QuickAdd"))'

Then I eyeball the list to find the command ID for what I want.
I then copy-paste into

obsidian command id="ID"

as a separate step.

I don’t know if this will be helpful in any way as this won’t solve the “2 steps” issue (:sweat_smile:) but you can get a filtered list of available commands using commands filter= … :blush:

E.g.: from the TUI:

> commands filter=daily

Outputs:

daily-notes
daily-notes:goto-next
daily-notes:goto-prev

Or from the CLI:

% obsidian commands filter=daily

Outputs:

daily-notes
daily-notes:goto-next
daily-notes:goto-prev

So, I guess it could also work with:

% obsidian commands filter=quick

The problem is I need the command ID. So it actually doesn’t help. I already know the command name I want to run, that’s my starting point. That is not what Obsidian CLI demands. Instead it wants an ID which is I guess a design choice? Not sure why this is. Thus the request here. But it does point out I need to change the title of this thread!

obsidian command id="ID"

Yes, I understand :blush:
Like I said, it wasn’t going solve your current issue :innocent:

I can only guess the use of id vs. name for the command in the CLI/TUI has to do with Obsidian API and how commands are managed/stored within Obsidian :blush: … and also that:

obsidian command id="ID"

… in the CLI/TUI is probably similar to using app.commands.executeCommandById("command-id") in the console (or through Templater (for example) and/or other “scripting” plugins) :blush:.

I could be wrong though … as I don’t have any more info about the need of id vs. name than you do :smile: .

Maybe if we just wait someone more knowledgable will chime in! Thanks for the idea, we can guess all day but to me it just looks like an oversight. You can get the id’s from the name, so why not just do that for me? The only thing I can think of is that names might not be unique for commands, but IDs will be. Having two names that are identical seems like a bad design too but maybe I’m wrong.

1 Like