How to toggle off spell check on startup?


Is it possible to turn off the spell checker when starting Atom? Essentially I just want it to stay off until I toggle it on. I have the key mapping below in my keymap.cson so I can easily toggle it. But I find myself doing it constantly.


‘ctrl-s’: ‘spell-check:toggle’


Put this in your on its own line:

atom.commands.dispatch document.querySelector('atom-text-editor'), 'spell-check:toggle'


I added this line to my But when I start Atom, then click on a tab with a .txt file, the red underlines appear again, and I toggle it off with my key mapped button press ctrl-alt-s.



Hmm. Damn, I temporarily forgot: Atom is very asynchronous in how it loads packages and there’s no canonical order, so in order to interact with a package in, it’s probably necessary to tell it to wait until all of the packages are loaded.

So I did all that, and it doesn’t work, and I’m not sure why.

atom.packages.onDidActivateInitialPackages ->
  if atom.commands.dispatch document.querySelector('atom-text-editor'), 'spell-check:toggle'
    console.log "The spell-check package should be toggled off."
    console.log "Something's amiss."

As you can see if you use atom.commands.dispatch(document.querySelector('atom-text-editor'), 'spell-check:toggle') from the console, dispatch() returns true if the command can be executed. So the confirmatory console.log should show up only if the package is successfully toggled off. Instead, I see the confirmation and I still see red marks in my document. I’m not sure why this is happening.


Just because the packages have all been activated doesn’t mean that the editors are opened. You may want to hook atom.workspace.observeTextEditors instead and do something to ensure that you only toggle it once.


So it toggles for each individual editor and not globally? That would explain things, except this doesn’t work either:

atom.workspace.observeTextEditors ->
  atom.commands.dispatch document.querySelector('atom-text-editor'), 'spell-check:toggle'


No, as far as I know it toggles globally. But if there is no atom-text-editor element in the DOM, then dispatching a command from document.querySelector('atom-text-editor') won’t get you very far :grinning:

I just tried this out and it appears to work:

onePingOnly = false

atom.workspace.observeTextEditors ->
  unless onePingOnly
    onePingOnly = true
    atom.commands.dispatch(document.querySelector('atom-workspace'), 'spell-check:toggle')

When using atom.commands.dispatch, it is important to match the selector with the element that Atom expects the command to be caught by. And spell-check:toggle is intended to be caught by atom-workspace not atom-text-editor.

It’s also important to keep in mind that atom.commands.dispatch was only intended to be used for testing packages, not for actually creating functionality.


Except that it returns true when I do that, as indicated by the console.log output. I just tried it with document.querySelector('atom-workspace') and got the same result: dispatch() returns true but the package is not toggled off.


atom.commands.dispatch(document.querySelector('atom-text-editor'), 'spell-check:toggle') in the dev tools console does toggle the package as expected.

It’s also important to keep in mind that atom.commands.dispatch was only intended to be used for testing packages, not for actually creating functionality.

I’m not sure how this is relevant. What’s the difference between toggling a package in a script and doing it in the console, provided the package is loaded and activated?