Skip to content

Instantly share code, notes, and snippets.

@kovalbogdan95
Last active February 5, 2020 01:59
Show Gist options
  • Save kovalbogdan95/6a120f5aa6823cad29308aa1188a5c32 to your computer and use it in GitHub Desktop.
Save kovalbogdan95/6a120f5aa6823cad29308aa1188a5c32 to your computer and use it in GitHub Desktop.
Set random terminal profile on Ubuntu
#!/usr/bin/python3
# Credits to https://github.com/aruhier/gnome-terminal-colors-solarized
# Install ALL themes using this tool https://github.com/Mayccoll/Gogh
# You may nedd to install dconf - sudo apt-get install dconf-cli
import subprocess
import ast
import random
import os
# Get curret theme name by its id
get_theme_id_comand = f"gsettings get org.gnome.Terminal.ProfilesList default"
process = subprocess.Popen(get_theme_id_comand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
id_ = output.decode().strip().replace("'", "")
read_theme_name_comand = f'dconf read /org/gnome/terminal/legacy/profiles:/:{id_}/visible-name'
process = subprocess.Popen(read_theme_name_comand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
current_theme = output.decode()
# Get list of theme ids and chose new one randomly
list_comand = "gsettings get org.gnome.Terminal.ProfilesList list"
process = subprocess.Popen(list_comand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
theme_id_array = ast.literal_eval(output.decode().strip('\n'))
new_theme_id = random.choice(theme_id_array)
# Update settings
settings_array = [
f"dconf write /org/gnome/terminal/legacy/profiles:/:{new_theme_id}/default-size-columns 120",
f"dconf write /org/gnome/terminal/legacy/profiles:/:{new_theme_id}/default-size-rows 30",
f"dconf write /org/gnome/terminal/legacy/profiles:/:{new_theme_id}/audible-bell false",
]
for item in settings_array:
os.system(item)
# Set theme
os.system(f"gsettings set org.gnome.Terminal.ProfilesList default {new_theme_id}")
# Get name of the current theme
read_theme_name_comand = f"dconf read /org/gnome/terminal/legacy/profiles:/:{new_theme_id}/visible-name"
process = subprocess.Popen(read_theme_name_comand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
# Print it out
print(" Current theme: ", current_theme, "New theme: ", output.decode().strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment