#!/usr/bin/env zsh pidfile=${XDG_RUNTIME_DIR-/run/user/$UID}/xscreensaver-companion.pid trap "rm -f $pidfile" INT KILL function init_pidfile { local pid if read pid < $pidfile; then if kill -0 $pid; then echo 'I am already running!' >&2 exit 1 else echo 'Remove stale lock file.' >&2 rm $pidfile fi fi echo $$ > $pidfile } function parse_actions { while read action _; do case $action in (LOCK|BLANK) /usr/bin/setxkbmap us -option /usr/bin/numlockx off /usr/bin/notify-send DUNST_COMMAND_PAUSE ;; (UNBLANK) $HOME/git/mine/vscripts/mykblayouts /usr/bin/notify-send DUNST_COMMAND_RESUME ;; esac done } init_pidfile /usr/bin/xscreensaver-command -watch | parse_actions