Execute command from CoffeeScript


I want to bind multiple commands to one keystroke.

I understand that I need to edit my init.coffee file, but I have no idea how to find the CoffeeScript equivalent of the commands I want to execute.

It would be nice if there were a helper so I could just


or something similar.


I discovered atom.commands.dispatch!

This gets me 90% of the way there. I just need to figure out how to pass the current ActiveTextEditor as the target


Yep, atom.commands.dispatch is what you want. You can get the current editor with atom.workspace.getActiveTextEditor().


It seems maybe the current editor is not what I should be passing as target in this case, as that just throws “undefined is not a function

Seems to work if I pass this as target, which feels all sorts of dirty and wrong, but gets the job done.


Here is what I am working with:

atom.commands.add 'atom-text-editor', 'custom:save-and-commit', ->
  editor = atom.workspace.getActiveTextEditor()
  atom.commands.dispatch(this, 'git-plus:add-all-and-commit')


Argh, accidentally edited my post.

atom.commands.add 'atom-text-editor', 'custom:save-and-commit', ->
  workspace = atom.views.getView(atom.workspace)
  atom.commands.dispatch(workspace, 'git-plus:add-all-and-commit')

I think you should be able to use the text editor too though. You probably need to also use the view for that. So you could use atom.views.getView(atom.workspace.getActiveTextEditor()) as the target.