Sublime Forum

Command to set multiple global settings

#1

I wanted to define a couple of user commands that would toggle several global settings at the same time. I made them into command palette items using User/Default.sublime-commands, but I could have used key shortcuts as well:

[{
  "caption": "Night Mode",
  "command": "set_multiple_settings",
  "args": {
    "font_face": "GohuFont",
    "font_options": ["no_italic", "no_antialias"],
    "font_size": 10,
    "theme": "SoDaReloaded Dark.sublime-theme",
    "color_scheme": "Sunburst Bright.tmTheme"
  }
},{
  "caption": "Day Mode",
  "command": "set_multiple_settings",
  "args": {
    "font_face": "Inconsolata",
    "font_options": [],
    "font_size": 11.5,
    "theme": "SoDaReloaded Light.sublime-theme",
    "color_scheme": "Dawn.tmTheme"
  }
}]

I couldn’t find a simple way to do this, so I wrote a very simple plugin:

# set_multiple_settings.py
import sublime, sublime_plugin

# Takes a map of settings as "args" and applies them globally,
# overwriting those in Preferences.sublime-settings
class SetMultipleSettingsCommand(sublime_plugin.ApplicationCommand):

  def run(self, **args):
    settings = sublime.load_settings('Preferences.sublime-settings')
    for name, value in args.items():
      settings.set(name, value)
    sublime.save_settings('Preferences.sublime-settings')

I’m not knowledgeable at all about ST internals, I just know Python. I took inspiration from run_multiple_commands and from a CycleSetting.py that I happened to have in my User folder, that I don’t remember where it came from.

0 Likes