Sublime Forum

Automatic Theme Selection for ST2 on Mac


After playing around with the other day I thought it would be pretty cool if I could set the Sublime Text 2 depending on the time of day. For example, at sunset I would like to have the Solarised (Dark) theme, and then at sunrise have the Solarized (Light) theme.

CAVEAT: try this at your own risk! I’ve tested it out and it works fine for me but as you can tell from my script, I’m certainly no expert. Any suggested improvements are welcome.

  1. Set up an IFTTT rule for sunset; Simply put I just use the weather trigger for sunset and then use a dropbox action to add a file to my IFTTT/Daylight folder called sunset.txt with ‘Dark’ in there. Do the same for sunrise with ‘Light’
  2. Add an automator folder action on your Dropbox/IFTTT/Daylight folder of the type ‘shell script’ with the following code in;


CURRENTSETTING=grep tmTheme ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Preferences.sublime-settings | awk -F'(|)]' '{print $2}'
sed -i ‘.bak’ ‘s/(’$CURRENTSETTING’).tmTheme/(’$NEXTSETTING’).tmTheme/’ ‘/Users/luke/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings’
fi [/code]

  1. That’s it!

Note: this doesn’t change syntax specific theme settings but I am sure it could be expanded to do so.