Created
November 20, 2020 22:07
-
-
Save jhonasn/e352f368ff33dfd1ec4d1772602caab6 to your computer and use it in GitHub Desktop.
script to switch gnome, gedit and atom theme between light and dark. made for better day/night readability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from sys import argv, exit | |
from os import popen | |
from os.path import join, expanduser as get_path | |
from re import search | |
if '-h' in argv or '--help' in argv: | |
print(''' | |
Executing this program will invert dark/light colors | |
of OS between yaru-light and dark; | |
gedit between kate and cobalt | |
and atom between one-light and dark. | |
-d to set dark theme | |
-l to set light theme | |
''') | |
exit() | |
def command (cmd): | |
return popen(cmd).read() | |
home_path = get_path('~') | |
gnome_command = 'gsettings {} org.gnome.desktop.interface gtk-theme ' | |
# identify color mode | |
is_dark = 'dark' in command( | |
gnome_command.format('get') | |
) | |
print('OS theme is dark: ' + str(is_dark)) | |
if '-d' in argv or '-l' in argv: | |
is_dark = '-l' in argv | |
print('Force {} theme'.format('light' if is_dark else 'dark')) | |
def change_atom_file (is_dark): | |
path = join(home_path, '.atom/config.cson') | |
f = open(path, 'r').read() | |
ui_re = search('\"[a-z\-]+\-ui\"', f) | |
syntax_re = search('\"[a-z\-]+\-syntax\"', f) | |
ui = f[ui_re.start() + 1:ui_re.end() - 1] | |
syntax = f[syntax_re.start() + 1:syntax_re.end() - 1] | |
new_ui = ui | |
new_syntax = syntax | |
if is_dark: | |
if 'light' not in ui: new_ui = ui.replace('dark', 'light') | |
if 'light' not in syntax: new_syntax = syntax.replace('dark', 'light') | |
else: | |
if 'dark' not in ui: new_ui = ui.replace('light', 'dark') | |
if 'dark' not in syntax: new_syntax = syntax.replace('light', 'dark') | |
f = f.replace(ui, new_ui) | |
file = f.replace(syntax, new_syntax) | |
f = open(path, 'w') | |
f.write(file) | |
f.close() | |
# set mode colors | |
cmd_set_os = gnome_command.format('set') | |
gedit_command = 'gsettings set org.gnome.gedit.preferences.editor scheme ' | |
if is_dark: | |
command(cmd_set_os + 'Yaru-light') | |
command(gedit_command + 'kate') | |
else: | |
command(cmd_set_os + 'Yaru-dark') | |
command(gedit_command + 'cobalt') | |
change_atom_file(is_dark) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment