Platform specific settings


Can someone please explain how I can set platform specific settings?

For example I run on OSX and Windows, and I would like to configure the ‘atom-terminal’ package.

I want to set it up so in Windows it runs PowerShell and on OSX (both are not the defaults for the package).

How do I do this? It looked like maybe I could have “*”, “platform-darwin” and “platform-win32” as roots in my config.cson but it doesn’t seem to work…


This is not supported in Atom itself. Platform specific settings needs to be provided as a feature in packages for the time being.


You can do something like

if document.body.classList.contains 'platform-darwin'
  atom.config.set 'core.x', y
else if document.body.classList.contains 'platform-win32'
  atom.config.set 'core.x', z

in your, not as nice as what you describe, but it’s something :wink:


Yeah that will work. Thanks :smile:

It’s just super gross that each time I load atom my config will change. Which is even more messed up when I change platforms…


Here’s another idea: you can make a darwin and a win32 entry in your config.cson. Then in

if platform = document.body.className.match(/platform-(darwin|win32|linux)/)?[1]
  config = fs.readFileSync atom.config.getUserConfigPath()
  config = JSON.parse config.toString()
  if config[platform]?
    for own key, value of config[platform]
      atom.config.set key, value


Or you might get even fancier, and have platform-scoped, grammar-scoped configs:

if platform = document.body.className.match(/platform-(darwin|win32|linux)/)?[1]
  path = require 'path'
  CSON = require path.join atom.getLoadSettings().resourcePath, '/node_modules/season'
  config = CSON.readFileSync atom.config.getUserConfigPath()
  if config[platform]?
    for own scopeSelector, scopeConfig of config[platform]
      for own namespace, namespaceConfig of scopeConfig
        for own key, value of namespaceConfig
          atom.config.set "#{namespace}.#{key}", value, scopeSelector

Then you can have this in your config.cson:

    'softWrap': true # enable softWrap
    'softWrap': false # except in python files
      'softWrap': false # disable softWrap on mac
      'softWrap': true # except in python files :)

I haven’t tested any of this code though so maybe you need to fix some things

EDIT Ok so of course you need a .cson parser if you want to parse config.cson… updated the code (you should copy it all, the old code had a bug that wiped your config.cson)


Thanks! Seems to work well.


Very cool, @olmokramer. Thanks for that. If I understand, this will take whatever is in the platform dependent sections and add them to the default section. I have settings for Windows that need to preempt the defaults. It looks like I have to add the default settings to the other platforms in order for them to take effect properly? I should mention that I share the same config files between platforms (as described in my and others’ StackOverflow answers.

Atom doesn’t retain the config file in memory? If so, then only the memory representation of the “active” settings need be modified (and the file, not touched)


Atom reads from the file constantly. If you change the content of config.cson, it will be reflected in Atom’s behavior.