How to call an added command from ribbon icon click

how to call an added command using addCommand from ribbon
OR
how can I do an editorCallback like functionality from addRibbonIcon

Is this possible or am I doing something completely wrong ?

this.addCommand({
			id: 'sample-editor-command',
			name: 'Sample editor command',
			editorCallback: (editor: Editor, view: MarkdownView) => {
				console.log(editor.getSelection());
				editor.replaceSelection('Sample Editor Command');
			}
		});
this.addRibbonIcon("dice", "Print to console", (evt: MouseEvent) => {			
			// how do I call "sample-editor-command" here ?
		});

8 days not a single reply. :frowning:
seems like this is not doable , there might be some unexplored way thats needs some digging.

1 Like

Just in case someone else needs this, here’s the solution.

this.addRibbonIcon('dice', 'To Live API', () => {

  app.commands.commands["obsidian-to-api:send-all-to-Live-api"].editorCallback(); 
   //basically trawl through the app object, ensure you select command using the bracket notation and call the function [either callback or editorCallback()]
   // so more generically ==> app.commands.commands["plugin-id:command-id"].editorCallback()

});

There is probably an easier way but this is the way I found.

1 Like