2020-10-15 16:08:01 +01:00
<!doctype html>
< html class = "default no-js" >
< head >
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< title > joplin.commands | Joplin Plugin API Documentation< / title >
< meta name = "description" content = "Documentation for Joplin Plugin API Documentation" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" href = "../assets/css/main.css" >
< / head >
< body >
< header >
< div class = "tsd-page-toolbar" >
< div class = "container" >
< div class = "table-wrap" >
< div class = "table-cell" id = "tsd-search" data-index = "../assets/js/search.json" data-base = ".." >
< div class = "field" >
< label for = "tsd-search-field" class = "tsd-widget search no-caption" > Search< / label >
< input id = "tsd-search-field" type = "text" / >
< / div >
< ul class = "results" >
< li class = "state loading" > Preparing search index...< / li >
< li class = "state failure" > The search index is not available< / li >
< / ul >
< a href = "joplin.html" class = "title" > Joplin Plugin API Documentation< / a >
< / div >
< div class = "table-cell" id = "tsd-widgets" >
< div id = "tsd-filter" >
< a href = "#" class = "tsd-widget options no-caption" data-toggle = "options" > Options< / a >
< div class = "tsd-filter-group" >
< div class = "tsd-select" id = "tsd-filter-visibility" >
< span class = "tsd-select-label" > All< / span >
< ul class = "tsd-select-list" >
< li data-value = "public" > Public< / li >
< li data-value = "protected" > Public/Protected< / li >
< li data-value = "private" class = "selected" > All< / li >
< / ul >
< / div >
< input type = "checkbox" id = "tsd-filter-inherited" checked / >
< label class = "tsd-widget" for = "tsd-filter-inherited" > Inherited< / label >
< / div >
< / div >
< a href = "#" class = "tsd-widget menu no-caption" data-toggle = "menu" > Menu< / a >
< / div >
< / div >
< / div >
< / div >
< div class = "tsd-page-title" >
< div class = "container" >
< ul class = "tsd-breadcrumb" >
<!--
< li >
< a href = "../globals.html" > Globals< / a >
< / li >
-->
< li >
< a href = "joplincommands.html" > joplin.commands< / a >
< / li >
< / ul >
< h1 > <!-- Class --> joplin.commands< / h1 >
< / div >
< / div >
< / header >
< div class = "container container-main" >
< div class = "row" >
< div class = "col-8 col-content" >
< section class = "tsd-panel tsd-comment" >
< div class = "tsd-comment tsd-typography" >
< div class = "lead" >
2020-11-06 21:52:57 +00:00
< p > This class allows executing or registering new Joplin commands. Commands
can be executed or associated with
< a href = "joplinviewstoolbarbuttons.html" > toolbar buttons< / a > or
< a href = "joplinviewsmenuitems.html" > menu items< / a > .< / p >
2020-10-15 16:08:01 +01:00
< / div >
2020-11-06 21:52:57 +00:00
< p > < a href = "https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/register_command" > View the demo plugin< / a > < / p >
2020-10-15 16:08:01 +01:00
< a href = "#executing-joplin39s-internal-commands" id = "executing-joplin39s-internal-commands" style = "color: inherit; text-decoration: none;" >
< h2 > Executing Joplin' s internal commands< / h2 >
< / a >
2020-11-06 21:52:57 +00:00
< p > 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:< / p >
2020-10-21 01:46:53 +01:00
< ul >
2020-11-06 21:52:57 +00:00
< li > < a href = "https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/MainScreen/commands" > Main screen commands< / a > < / li >
< li > < a href = "https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/commands" > Global commands< / a > < / li >
< li > < a href = "https://github.com/laurent22/joplin/tree/dev/packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.ts" > Editor commands< / a > < / li >
2020-10-21 01:46:53 +01:00
< / ul >
2020-11-06 21:52:57 +00:00
< p > To view what arguments are supported, you can open any of these files
and look at the < code > execute()< / code > command.< / p >
2021-06-07 11:40:20 +02:00
< a href = "#executing-editor-commands" id = "executing-editor-commands" style = "color: inherit; text-decoration: none;" >
< h2 > Executing editor commands< / h2 >
< / a >
< p > There might be a situation where you want to invoke editor commands
without using a < a href = "joplincontentscripts.html" > contentScript< / a > . For this
reason Joplin provides the built in < code > editor.execCommand< / code > command.< / p >
< p > < code > editor.execCommand< / code > should work with any core command in both the
< a href = "https://codemirror.net/doc/manual.html#execCommand" > CodeMirror< / a > and
< a href = "https://www.tiny.cloud/docs/api/tinymce/tinymce.editorcommands/#execcommand" > TinyMCE< / a > editors,
as well as most functions calls directly on a CodeMirror editor object (extensions).< / p >
< ul >
< li > < a href = "https://codemirror.net/doc/manual.html#commands" > CodeMirror commands< / a > < / li >
< li > < a href = "https://www.tiny.cloud/docs/advanced/editor-command-identifiers/#coreeditorcommands" > TinyMCE core editor commands< / a > < / li >
< / ul >
< p > < code > editor.execCommand< / code > supports adding arguments for the commands.< / p >
< pre > < code class = "language-typescript" > < span class = "hljs-keyword" > await< / span > joplin.commands.execute(< span class = "hljs-string" > ' editor.execCommand' < / span > , {
< span class = "hljs-attr" > name< / span > : < span class = "hljs-string" > ' madeUpCommand' < / span > , < span class = "hljs-comment" > // CodeMirror and TinyMCE< / span >
< span class = "hljs-attr" > args< / span > : [], < span class = "hljs-comment" > // CodeMirror and TinyMCE< / span >
< span class = "hljs-attr" > ui< / span > : < span class = "hljs-literal" > false< / span > , < span class = "hljs-comment" > // TinyMCE only< / span >
< span class = "hljs-attr" > value< / span > : < span class = "hljs-string" > ' ' < / span > , < span class = "hljs-comment" > // TinyMCE only< / span >
});< / code > < / pre >
< p > < a href = "https://github.com/laurent22/joplin/blob/dev/packages/app-cli/tests/support/plugins/codemirror_content_script/src/index.ts" > View the example using the CodeMirror editor< / a > < / p >
2020-10-15 16:08:01 +01:00
< / div >
< / section >
<!--
< section class = "tsd-panel tsd-hierarchy" >
< h3 > Hierarchy< / h3 >
< ul class = "tsd-hierarchy" >
< li >
< span class = "target" > JoplinCommands< / span >
< / li >
< / ul >
< / section >
-->
< section class = "tsd-panel-group tsd-index-group" >
< h2 > Index< / h2 >
< section class = "tsd-panel tsd-index-panel" >
< div class = "tsd-index-content" >
< section class = "tsd-index-section " >
< h3 > Methods< / h3 >
< ul class = "tsd-index-list" >
< li class = "tsd-kind-method tsd-parent-kind-class" > < a href = "joplincommands.html#execute" class = "tsd-kind-icon" > execute< / a > < / li >
< li class = "tsd-kind-method tsd-parent-kind-class" > < a href = "joplincommands.html#register" class = "tsd-kind-icon" > register< / a > < / li >
< / ul >
< / section >
< / div >
< / section >
< / section >
< section class = "tsd-panel-group tsd-member-group " >
< h2 > Methods< / h2 >
< section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class" >
< a name = "execute" class = "tsd-anchor" > < / a >
< h3 > execute< / h3 >
< ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class" >
2020-10-21 00:56:03 +01:00
< li class = "tsd-signature tsd-kind-icon" > execute< span class = "tsd-signature-symbol" > (< / span > commandName< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > string< / span > , < span class = "tsd-signature-symbol" > ...< / span > args< span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > > < / span > < / li >
2020-10-15 16:08:01 +01:00
< / ul >
< ul class = "tsd-descriptions" >
< li class = "tsd-description" >
< aside class = "tsd-sources" >
< / aside >
< div class = "tsd-comment tsd-typography" >
< div class = "lead" >
2020-11-06 21:52:57 +00:00
< p > < span class = "platform-desktop" > desktop< / span > Executes the given
command.< / p >
2020-10-15 16:08:01 +01:00
< / div >
2020-11-06 21:52:57 +00:00
< p > The command can take any number of arguments, and the supported
arguments will vary based on the command. For custom commands, this
is the < code > args< / code > passed to the < code > execute()< / code > function. For built-in
commands, you can find the supported arguments by checking the links
above.< / p >
2020-10-15 16:08:01 +01:00
< pre > < code class = "language-typescript" > < span class = "hljs-comment" > // Create a new note in the current notebook:< / span >
< span class = "hljs-keyword" > await< / span > joplin.commands.execute(< span class = "hljs-string" > ' newNote' < / span > );
< span class = "hljs-comment" > // Create a new sub-notebook under the provided notebook< / span >
< span class = "hljs-comment" > // Note: internally, notebooks are called " folders" .< / span >
2020-10-21 00:27:11 +01:00
< span class = "hljs-keyword" > await< / span > joplin.commands.execute(< span class = "hljs-string" > ' newFolder' < / span > , < span class = "hljs-string" > " SOME_FOLDER_ID" < / span > );< / code > < / pre >
2020-10-15 16:08:01 +01:00
< / div >
< h4 class = "tsd-parameters-title" > Parameters< / h4 >
< ul class = "tsd-parameters" >
< li >
< h5 > commandName: < span class = "tsd-signature-type" > string< / span > < / h5 >
< / li >
< li >
2020-10-21 00:27:11 +01:00
< h5 > < span class = "tsd-flag ts-flagRest" > Rest< / span > < span class = "tsd-signature-symbol" > ...< / span > args: < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > []< / span > < / h5 >
2020-10-15 16:08:01 +01:00
< / li >
< / ul >
<!-- JOPLINCHANGE
2020-10-21 00:56:03 +01:00
< h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > any< / span > < span class = "tsd-signature-symbol" > | < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > > < / span > < / h4 >
2020-10-15 16:08:01 +01:00
-->
< / li >
< / ul >
< / section >
< section class = "tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class" >
< a name = "register" class = "tsd-anchor" > < / a >
< h3 > register< / h3 >
< ul class = "tsd-signatures tsd-kind-method tsd-parent-kind-class" >
< li class = "tsd-signature tsd-kind-icon" > register< span class = "tsd-signature-symbol" > (< / span > command< span class = "tsd-signature-symbol" > : < / span > < a href = "../interfaces/command.html" class = "tsd-signature-type" > Command< / a > < span class = "tsd-signature-symbol" > )< / span > < span class = "tsd-signature-symbol" > : < / span > < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > > < / span > < / li >
< / ul >
< ul class = "tsd-descriptions" >
< li class = "tsd-description" >
< aside class = "tsd-sources" >
< / aside >
< div class = "tsd-comment tsd-typography" >
< div class = "lead" >
< p > < span class = "platform-desktop" > desktop< / span > Registers a new command.< / p >
< / div >
< pre > < code class = "language-typescript" > < span class = "hljs-comment" > // Register a new commmand called " testCommand1" < / span >
< span class = "hljs-keyword" > await< / span > joplin.commands.register({
2020-11-05 16:58:23 +00:00
< span class = "hljs-attr" > name< / span > : < span class = "hljs-string" > ' testCommand1' < / span > ,
< span class = "hljs-attr" > label< / span > : < span class = "hljs-string" > ' My Test Command 1' < / span > ,
< span class = "hljs-attr" > iconName< / span > : < span class = "hljs-string" > ' fas fa-music' < / span > ,
< span class = "hljs-attr" > execute< / span > : < span class = "hljs-function" > () => < / span > {
2020-10-15 16:08:01 +01:00
alert(< span class = "hljs-string" > ' Testing plugin command 1' < / span > );
},
});< / code > < / pre >
< / div >
< h4 class = "tsd-parameters-title" > Parameters< / h4 >
< ul class = "tsd-parameters" >
< li >
< h5 > command: < a href = "../interfaces/command.html" class = "tsd-signature-type" > Command< / a > < / h5 >
< / li >
< / ul >
<!-- JOPLINCHANGE
< h4 class = "tsd-returns-title" > Returns < span class = "tsd-signature-type" > Promise< / span > < span class = "tsd-signature-symbol" > < < / span > < span class = "tsd-signature-type" > void< / span > < span class = "tsd-signature-symbol" > > < / span > < / h4 >
-->
< / li >
< / ul >
< / section >
< / section >
< / div >
< div class = "col-4 col-menu menu-sticky-wrap menu-highlight" >
<!--
< nav class = "tsd-navigation primary" >
< ul >
< li class = "globals " >
< a href = "../globals.html" > < em > Globals< / em > < / a >
< / li >
< / ul >
< / nav >
-->
< nav class = "tsd-navigation secondary menu-sticky" >
< ul class = "before-current" >
< / ul >
< ul class = "current" >
< li class = "current tsd-kind-class" >
< a href = "joplincommands.html" class = "tsd-kind-icon" > joplin.commands< / a >
< ul >
< li class = " tsd-kind-method tsd-parent-kind-class" >
< a href = "joplincommands.html#execute" class = "tsd-kind-icon" > execute< / a >
< / li >
< li class = " tsd-kind-method tsd-parent-kind-class" >
< a href = "joplincommands.html#register" class = "tsd-kind-icon" > register< / a >
< / li >
< / ul >
< / li >
< / ul >
< ul class = "after-current" >
< / ul >
< / nav >
< / div >
< / div >
< / div >
<!-- JOPLINCHANGE
< footer class = "with-border-bottom" >
< div class = "container" >
< h2 > Legend< / h2 >
< div class = "tsd-legend-group" >
< ul class = "tsd-legend" >
< li class = "tsd-kind-property tsd-parent-kind-interface" > < span class = "tsd-kind-icon" > Property< / span > < / li >
< li class = "tsd-kind-method tsd-parent-kind-interface" > < span class = "tsd-kind-icon" > Method< / span > < / li >
< / ul >
< ul class = "tsd-legend" >
< li class = "tsd-kind-constructor tsd-parent-kind-class" > < span class = "tsd-kind-icon" > Constructor< / span > < / li >
< li class = "tsd-kind-method tsd-parent-kind-class" > < span class = "tsd-kind-icon" > Method< / span > < / li >
< / ul >
< / div >
< / div >
< / footer >
< div class = "container tsd-generator" >
< p > Generated using < a href = "https://typedoc.org/" target = "_blank" > TypeDoc< / a > < / p >
< / div >
-->
< div class = "overlay" > < / div >
< script src = "../assets/js/main.js" > < / script >
< / body >
< / html >