commands API

The commands API first appeared in Thunderbird 66. It’s more or less the same as the Firefox commands API.

Use the commands API to add keyboard shortcuts that trigger actions in your extension, for example opening one of the action popups or sending a command to the extension.

Manifest file properties

[commands]

(object)

A dictionary object defining one or more commands as name-value pairs, the name being the name of the command and the value being a CommandsShortcut. The name may also be one of the following built-in special shortcuts:

  • _execute_browser_action

  • _execute_compose_action

  • _execute_message_display_action

Example:

"commands": {
  "toggle-feature": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y",
      "linux": "Ctrl+Shift+U"
    },
    "description": "Send a 'toggle-feature' event"
  },
  "_execute_compose_action": {
    "suggested_key": {
      "default": "Alt+F5"
    },
    "description": "Open the compose action popup"
  }
}

Note

A manifest entry named commands is required to use messenger.commands.*.

Functions

update(detail)

Update the details of an already defined command.

Parameters

detail

(object)

The new details for the command.

name

(string)

The name of the command.

[description]

(string)

The description for the command.

[shortcut]

(string)

An empty string to clear the shortcut, or a string matching the format defined by the MDN page of the commands API to set a new shortcut key. If the string does not match this format, the function throws an error.

reset(name)

Reset a command’s details to what is specified in the manifest.

Parameters

name

(string)

The name of the command.

getAll()

Returns all the registered extension commands for this extension and their shortcut (if active).

Return type (Promise)

array of Command

Events

onCommand

Fired when a registered command is activated using a keyboard shortcut. This is a user input event handler. For asynchronous listeners some restrictions apply.

Parameters for onCommand.addListener(listener)

listener(command, tab)

A function that will be called when this event occurs.

Parameters passed to the listener function

command

(string)

tab

(Tab)

– [Added in TB 106, backported to TB 102.3.3]

The details of the active tab while the command occurred.

Types

Command

object

[description]

(string)

The Extension Command description

[name]

(string)

The name of the Extension Command

[shortcut]

(string)

The shortcut active for this command, or blank if not active.

CommandsShortcut

object

[description]

(string)

[suggested_key]

(object)

[default]

Default key combination.

[linux]

Key combination on Linux.

[mac]

Key combination on Mac.

[windows]

Key combination on Windows.

KeyName

Definition of a shortcut, for example Alt+F5. The string must match the shortcut format as defined by the MDN page of the commands API.

string