How to dispatch a command on ATOM?


I’m having problems trying to dispatch a command.

Here is the code.

     activate: (state) ->
       @subscriptions = new CompositeDisposable    
       @subscriptions.add atom.commands.add "atom-workspace",
         "activate-killer-instinct-mode:test-command": =>
           console.log "Hello, I'm your commands"
           @error = false

       target = "atom-workspace"
       commandName = "activate-killer-instinct-mode:test-command"

       atom.commands.dispatch target, commandName #Here is the error

       console.log "The command " + commandName + " got dispatched" if not @error
       console.error "The command " + commandName + " didn't get dispatched" if @error

I got this output.
The command activate-killer-instinct-mode:test-command didn’t get dispatched

I made a question on stackoverflow, if want to read more details.

Thanks for the help.


As target you need to specify the DOM node:

target = atom.views.getView atom.workspace
commandName = "activate-killer-instinct-mode:test-command"

atom.commands.dispatch target, commandName


Thank you so much @idleberg, it really works.


I think the documentation could has an example.


so this is an object?.
how can I make an DOM node of atom.views.getView atom.workspace?

with something like.

    subscriptions = new CompositeDisposable
    target = atom.views.getView atom.workspace