Using a timer that regularly read the file for what colour mode is in use I solved the question.
Here is the script that reads and calls the changes:
" Set colour scheme (and more) to light mode
function! ColorModeLight()
colorscheme onehalflight
let g:color_mode_light=1
...
endfunction
" Set colour scheme (and more) to dark mode
function! ColorModeDark()
colorscheme onehalfdark
let g:color_mode_light=0
...
endfunction
" Check for system colour mode changed
function! ColorModeCheck(timer)
for line in readfile('/tmp/SYSTEM_LIGHT_MODE', '', 1)
if line =~ '0' && get(g:, 'color_mode_light', 0) == 1
call ColorModeDark()
elseif line =~ '1' && get(g:, 'color_mode_light', 0) == 0
call ColorModeLight()
endif
endfor
endfunction
" Set default colour
colorscheme onehalfdark
let g:color_mode_light=0
...
" Regularly check file for changes
let timer = timer_start(500, 'ColorModeCheck', {'repeat': -1})
My sxhkd runs a script that truncates and writes either 1
or 0
to /tmp/SYSTEM_LIGHT_MODE
when called by toggling between the two, after this script is fired vim will soon read that a change occurred and update the colorscheme (lightline and more).