Automatically adjust Alacritty theme according to your current MacOS system theme. (dark/light)
This is a shell script running indefinitely in the background, checking for system theme change every 0.5 seconds using AppleScript.
If change is detected, it updates ~/.alacritty.toml with the appropriate theme.
- MacOS 14 (Sonoma)
zsh >= 5.9, set as your shellalacritty >= 0.13.2- Alacritty config must contain
live_config_reload = true
The autoswitcher might work on earlier versions of MacOS, but it is not guaranteed.
Before installing the autoswitcher, you need to prepare Alacritty configuration files in your home directory:
- Place all your configuration excluding theming part in
~/.alacritty-base.toml - Place only the light theme in
~/.alacritty-theme-light.toml - Place only the dark theme in
~/.alacritty-theme-dark.toml
Install the autoswitcher by running the installation script:
./install.shAlternatively, use any method of your choice to ensure .alacritty-theme-autoswitch.sh is launched at login, terminal launch etc.
See examples on how the config files should look like.
The installation script copies
.alacritty-theme-autoswitch.shto your home directory and adds a command to.zshrcto launch it automatically. Launching autoswitcher is idempotent, as it uses file lock to ensure it only runs once at a time.
The autoswitcher is started automatically.
To stop the script:
pkill -fx "zsh $HOME/.alacritty-theme-autoswitch.sh"Please note, that as long as
.zshrccontains the launch command, autoswitcher will re-launch every time you open a new shell session.
To remove autoswitcher:
- Remove launch command from
.zshrc - Delete the
.alacritty-theme-autoswitch.shfrom your home directory - Stop the autoswitcher using the command provided above
Implementing the same in pure AppleScript is possible and results in similar looping logic. It would have to be compiled as a "stay open application"; making it hidden in the background requires some effort and is arguably less clean. The shell script method is easier.
I dislike inline file editing. The method of joining two source files is robust and easy to understand.