Skip to content

Command

Official

A command that can be executed from the command palette or toolbar buttons.

Import:

import type { Command } from 'obsidian';

Signature:

export interface Command

Properties

PropertyTypeDescription
allowPreview?booleanWhether the editor command can be executed when the note is in preview mode.
allowProperties?booleanWhether the editor command can be executed when the properties panel is shown.
callback?() => anySimple callback, triggered globally.
checkCallback?(checking: boolean) => boolean | voidComplex callback, overrides the simple callback. Used to 'check' whether your command can be performed in the current circumstances. For example, if your command requires the active focused pane to be a MarkdownView, then you should only return true if the condition is satisfied. Returning false or undefined causes the command to be hidden from the command palette.
editorCallback?(editor: Editor, ctx: MarkdownView | MarkdownFileInfo) => anyA command callback that is only triggered when the user is in an editor. Overrides callback and checkCallback
editorCheckCallback?(checking: boolean, editor: Editor, ctx: MarkdownView | MarkdownFileInfo) => boolean | voidA command callback that is only triggered when the user is in an editor. Overrides editorCallback, callback and checkCallback
hotkeys?Hotkey[]Sets the default hotkey. It is recommended for plugins to avoid setting default hotkeys if possible, to avoid conflicting hotkeys with one that's set by the user, even though customized hotkeys have higher priority.
icon?IconNameIcon ID to be used in the toolbar.

See https://docs.obsidian.md/Plugins/User+interface/Icons for available icons and how to add your own.
idstringGlobally unique ID to identify this command.
mobileOnly?booleanWhether the command is only available on mobile.
namestringHuman friendly name for searching.
repeatable?booleanWhether holding the hotkey should repeatedly trigger this command.
showOnMobileToolbar?booleanWhether the non-editor command button can be shown on the mobile toolbar.

Links to this page: