Changing the theme with a keymap


#1

I’d like to be able to switch between, for example, a “dark” theme and a “light” theme with a keymap. I can’t see a keymap that does this already and I can’t find anything in the API to allow me to change the theme that way.

Is it possible? If so, can somebody point me in the right direction?


#2

I don’t think there’s (and will be) an API for that, however you can achieve that through a custom command in your init script:

atom.commands.add 'atom-workspace',
  'themes:toggle': ->
    activeThemes = atom.themes.getActiveNames()

    # This is for the example sake, otherwise don't do it like that
    if activeThemes.join(':').indexOf('dark') is -1 
      atom.themes.setEnabledThemes(["atom-dark-syntax", "atom-dark-ui"])
    else
      atom.themes.setEnabledThemes(["atom-light-syntax", "atom-light-ui"])

Now you have a themes:toggle command that you can bind to any keymap or access through the command palette.


#3

Wow, that’s exactly what I was looking for!

Thanks a lot :smile: