How to dispatch a command on ATOM?


#1

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.
https://stackoverflow.com/questions/45799346/how-to-dispatch-a-command-on-atom.

Thanks for the help.


#2

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

#3

Thank you so much @idleberg, it really works.


#4

I think the documentation could has an example.


#5

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
    subscriptions.appendChild(target)