Skip to content

Instantly share code, notes, and snippets.

@nffdiogosilva
Last active December 22, 2015 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nffdiogosilva/6536189 to your computer and use it in GitHub Desktop.
Save nffdiogosilva/6536189 to your computer and use it in GitHub Desktop.
Script that i made, responsible to change Sublime Solarized Theme depending on daytime. Should be use with anacron or fcron. Example using with cron job: 00 8,20 * * * python ~/.bin/changetheme.py
# -*- coding: utf-8 -*-
from os.path import expanduser
from datetime import datetime as day
HOME_DIR = expanduser("~")
SUBLIME_USER_PREFERENCES_PATH = '/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings'
class SublimeTheme(object):
def __init__(self, path=HOME_DIR + SUBLIME_USER_PREFERENCES_PATH, min_hour=8, max_hour=20):
self.path = path
self.min_hour = min_hour
self.max_hour = max_hour
self.is_daytime = True if day.now().hour >= min_hour and day.now().hour < max_hour else False
self.theme = 'Light' if self.is_daytime else 'Dark'
self.file = None
def _theme_configuration(self):
return '{ \n\t \
"color_scheme": "Packages/Color Scheme - Default/Solarized (%s).tmTheme", \n\t \
"draw_white_space": "all", \n\t \
"font_size": 12.0, \n\t \
"ignored_packages": \n\t \
[ \n\t \
"Vintage" \n\t \
] \n \
}' % self.theme
def change_theme(self):
self.file = open(self.path, 'w')
self.file.write(self._theme_configuration())
self.file.close()
def __str__(self):
return "Sublime Theme Object: %s Theme is now set" % self.theme
SublimeTheme().change_theme()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment