Base on this guide:
- In iTerm2 go to Scripts > Manage > New Python Script (python runtime may need installing)
- Choose Basic script type
- Chose Long-Running Daemon script interval
- Name the script in some descriptive way like auto_theme_switch.py and paste this as content:
#!/usr/bin/env python3.7
import asyncio
import iterm2
# This script was created with the "basic" environment which does not support adding dependencies
# with pip.
async def main(connection):
async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP, "effectiveTheme", None) as mon:
while True:
# Block until theme changes
theme = await mon.async_get()
# Themes have space-delimited attributes, one of which will be light or dark.
parts = theme.split(" ")
if "dark" in parts:
preset = await iterm2.ColorPreset.async_get(connection, "Smoooooth")
else:
preset = await iterm2.ColorPreset.async_get(connection, "Light Background")
# Update the list of all profiles and iterate over them.
profiles=await iterm2.PartialProfile.async_query(connection)
for partial in profiles:
# Fetch the full profile and then set the color preset in it.
profile = await partial.async_get_full_profile()
await profile.async_set_color_preset(preset)
# This instructs the script to run the "main" coroutine and to keep running even after it returns.
iterm2.run_forever(main)
the file lives in /Users/$USER/Library/Application\ Support/iTerm2/Scripts/
.
Use auto-dark-mode.nvim plugin by adding following to ~/.config/nvim/lua/plugins.lua
:
{
-- ...
-- automatic theme switching
{
"f-person/auto-dark-mode.nvim",
config = {
update_interval = 1000,
set_dark_mode = function()
vim.api.nvim_set_option("background", "dark")
vim.cmd("colorscheme everforest")
end,
set_light_mode = function()
vim.api.nvim_set_option("background", "light")
vim.cmd("colorscheme everforest")
end,
},
},
}
then Lazy install
and restart nvim.