Options
All
  • Public
  • Public/Protected
  • All
Menu

joplin.commands

This class allows executing or registering new Joplin commands. Commands can be executed or associated with toolbar buttons or menu items.

View the demo plugin

Executing Joplin's internal commands

It is also possible to execute internal Joplin's commands which, as of now, are not well documented. You can find the list directly on GitHub though at the following locations:

To view what arguments are supported, you can open any of these files and look at the execute() command.

Note that many of these commands only work on desktop. The more limited list of mobile commands can be found in these places:

Executing editor commands

There might be a situation where you want to invoke editor commands without using a contentScript. For this reason Joplin provides the built in editor.execCommand command.

editor.execCommand should work with any core command in both the CodeMirror and TinyMCE editors, as well as most functions calls directly on a CodeMirror editor object (extensions).

editor.execCommand supports adding arguments for the commands.

await joplin.commands.execute('editor.execCommand', {
    name: 'madeUpCommand', // CodeMirror and TinyMCE
    args: [], // CodeMirror and TinyMCE
    ui: false, // TinyMCE only
    value: '', // TinyMCE only
});

View the example using the CodeMirror editor

Index

Methods

Methods

execute

  • execute(commandName: string, ...args: any[]): Promise<any | void>
  • Executes the given command.

    The command can take any number of arguments, and the supported arguments will vary based on the command. For custom commands, this is the args passed to the execute() function. For built-in commands, you can find the supported arguments by checking the links above.

    // Create a new note in the current notebook:
    await joplin.commands.execute('newNote');
    
    // Create a new sub-notebook under the provided notebook
    // Note: internally, notebooks are called "folders".
    await joplin.commands.execute('newFolder', "SOME_FOLDER_ID");

    Parameters

    • commandName: string
    • Rest ...args: any[]

register

  • register(command: Command): Promise<void>
  • Registers a new command.

    // Register a new commmand called "testCommand1"
    
    await joplin.commands.register({
        name: 'testCommand1',
        label: 'My Test Command 1',
        iconName: 'fas fa-music',
        execute: () => {
            alert('Testing plugin command 1');
        },
    });

    Parameters