Command
Defined in: obsidian.d.ts:751
Properties
Section titled “Properties”callback()?
Section titled “callback()?”
optional
callback: () =>any
Defined in: obsidian.d.ts:790
Simple callback, triggered globally.
Returns
Section titled “Returns”any
Example
Section titled “Example”this.addCommand({ id: 'print-greeting-to-console', name: 'Print greeting to console', callback: () => { console.log('Hey, you!'); },});
checkCallback()?
Section titled “checkCallback()?”
optional
checkCallback: (checking
) =>boolean
|void
Defined in: obsidian.d.ts:825
Complex 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.
Parameters
Section titled “Parameters”checking
Section titled “checking”boolean
Whether the command palette is just ‘checking’ if your command should show right now. If checking is true, then this function should not perform any action. If checking is false, then this function should perform the action.
Returns
Section titled “Returns”boolean
| void
Whether this command can be executed at the moment.
Example
Section titled “Example”this.addCommand({ id: 'example-command', name: 'Example command', checkCallback: (checking: boolean) => { const value = getRequiredValue();
if (value) { if (!checking) { doCommand(value); } return true; }
return false; }});
editorCallback()?
Section titled “editorCallback()?”
optional
editorCallback: (editor
,ctx
) =>any
Defined in: obsidian.d.ts:844
A command callback that is only triggered when the user is in an editor.
Overrides callback
and checkCallback
Parameters
Section titled “Parameters”editor
Section titled “editor”MarkdownView
| MarkdownFileInfo
Returns
Section titled “Returns”any
Example
Section titled “Example”this.addCommand({ id: 'example-command', name: 'Example command', editorCallback: (editor: Editor, view: MarkdownView) => { const sel = editor.getSelection();
console.log(`You have selected: ${sel}`); }});
editorCheckCallback()?
Section titled “editorCheckCallback()?”
optional
editorCheckCallback: (checking
,editor
,ctx
) =>boolean
|void
Defined in: obsidian.d.ts:870
A command callback that is only triggered when the user is in an editor.
Overrides editorCallback
, callback
and checkCallback
Parameters
Section titled “Parameters”checking
Section titled “checking”boolean
editor
Section titled “editor”MarkdownView
| MarkdownFileInfo
Returns
Section titled “Returns”boolean
| void
Example
Section titled “Example”this.addCommand({ id: 'example-command', name: 'Example command', editorCheckCallback: (checking: boolean, editor: Editor, view: MarkdownView) => { const value = getRequiredValue();
if (value) { if (!checking) { doCommand(value); }
return true; }
return false; }});
hotkeys?
Section titled “hotkeys?”
optional
hotkeys:Hotkey
[]
Defined in: obsidian.d.ts:876
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.
optional
icon:string
Defined in: obsidian.d.ts:767
Icon 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.
id:
string
Defined in: obsidian.d.ts:756
Globally unique ID to identify this command.
mobileOnly?
Section titled “mobileOnly?”
optional
mobileOnly:boolean
Defined in: obsidian.d.ts:769
name:
string
Defined in: obsidian.d.ts:761
Human friendly name for searching.
repeatable?
Section titled “repeatable?”
optional
repeatable:boolean
Defined in: obsidian.d.ts:775
Whether holding the hotkey should repeatedly trigger this command.
Default Value
Section titled “Default Value”false@public