Programatically execute other packages command / event



I am trying to execute a command programatically from within my extension. Here’s the process I did:

  • Check ‘keybindings’ for the command / action I am looking for
  • In our case, let’s go with pane:close-other-items
  • Check the selector for the action, in this case body
  • Dispatch the event / command using dispatch or dispatchEvent

So with the example above I tried:

  • document.body.dispatchEvent(new CustomEvent("pane:close-other-items", {bubbles: true}))
  • atom.commands.dispatch("pane:close-other-items", document.body)

But none of that worked. I also tried to dispatch the event onto views.getView(atom.workspace) but it still doesn’t do anything


The first argument of atom.commands.dispatch is the DOM Node (or View), not the command name (see here). Also, pane:close-other-items does not work with atom.workspace

atom.commands.dispatch(atom.views.getView(atom.workspace.getActivePane()), 'pane:close-other-items')


Whoops, I wrote the code in the correct order but must have messed it up when writing this question.

The code from you works great! Thank you a lot :smile: The important bit I was missing was atom.workspace.getActivePane()