Skip to content

Commands

Unofficial

Manager for registering, finding, and executing commands.

Import:

import type { Commands } from '@obsidian-typings/obsidian-public-latest';

Signature:

export interface Commands extends Events

Extends: Events

Constructor

new Commands(app: App)

Constructor.

To get the constructor instance, use getCommandsConstructor from obsidian-typings/implementations.

Properties

PropertyTypeDescription
_Record<string, EventsEntry[]>Internal storage of registered event handlers by event name.
(Inherited from Events)
appAppReference to the obsidian#App.
commandsCommandsCommandsRecordCommands *without* editor callback, will always be available in the command palette.
editorCommandsCommandsEditorCommandsRecordCommands *with* editor callback, will only be available when editor is active and callback returns true.

Methods

MethodReturnsDescription
addCommand(command)voidAdd a command to the command registry.
executeCommand(command, event?)booleanExecute a command by reference.
executeCommandById(commandId, event?)booleanExecute a command by ID.
findCommand(commandId)Command | undefinedFind a command by ID.
listCommands()Command[]Lists **all** commands, both with and without editor callback.
off(name, callback)voidRemove an event listener.
(Inherited from Events)
offref(ref)voidRemove an event listener by reference.
(Inherited from Events)
on(name, callback, ctx?)EventRefAdd an event listener.
(Inherited from Events)
removeCommand(commandId)voidRemove a command from the command registry.
trigger(name, data?)voidTrigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Events)
tryTrigger(evt, args)voidTry to trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Events)

Links to this page: