#!/bin/zsh MODE_DEFAULT=('default.jpg' 'true' 'Solarized Matched' 'dark' 'df202020' 'ff999999') MODE_DARK=('dark.png' 'true' 'Solarized Matched' 'dark' '00202020' 'ff999999') MODE_LIGHT=('light.png' 'false' 'Solarized Light Matched' 'light' '00dfdfdf' 'ff666666') evaluate() { input="$1" shift replacements=($@) for i in {1..$#replacements}; do match="{$i}" replacement="${replacements[i]}" input="$(echo "$input" | sed "s/$match/$replacement/g")" done echo $input } change_system_theme() { mode=($@) rm -f ~/Pictures/wallpapers/current/* cp ~/.wallpaper/"${mode[1]}" ~/Pictures/wallpapers/current/"${mode[3]}${mode[1]}" template=" tell application \"System Events\" tell desktops set change interval to -1 set change interval to 1 end tell tell appearance preferences set dark mode to {2} end tell end tell " osascript -e "$(evaluate "$template" $mode)" } change_iterm2_theme() { mode=($@) template=' import iterm2 async def main(conn): app = await iterm2.async_get_app(conn) profiles = await iterm2.PartialProfile.async_query(conn) new_profile = None for profile in profiles: if profile.name == "{3}": new_profile = await profile.async_get_full_profile() await profile.async_make_default() windows = app.terminal_windows for window in windows: tabs = window.tabs for tab in tabs: sessions = tab.sessions for session in sessions: await session.async_set_profile(new_profile) iterm2.run_until_complete(main) ' script="$HOME/Library/Application Support/iTerm2/Scripts/change-theme.py" evaluate "$template" $mode > $script python3 $script } change_kitty_theme() { mode=($@) rm ~/.config/kitty/colorscheme.conf ln -s colorscheme.${mode[4]}.conf ~/.config/kitty/colorscheme.conf kitty @ set-colors -a ~/.config/kitty/colorscheme.conf } change_yabai_theme() { mode=($@) yabai -m config status_bar_background_color 0x${mode[5]} yabai -m config status_bar_foreground_color 0x${mode[6]} } mode_name="MODE_$1:u" mode=(${(P)mode_name}) if [[ -z $mode ]]; then echo "No mode specified" exit 1 fi if [[ "$(uname -s)" == "Darwin" ]]; then change_system_theme $mode change_yabai_theme $mode fi if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then change_iterm2_theme $mode fi if [[ "$TERM" == "xterm-kitty" ]]; then change_kitty_theme $mode fi