#!/usr/bin/env bash
SCRIPT="/usr/local/bin/stop-screensaver.sh"
STATEFILE="/tmp/stop-screensaver.state"

if pgrep -f "$SCRIPT" >/dev/null; then
  pkill -f "$SCRIPT"
else
  nohup "$SCRIPT" >/dev/null 2>&1 &
fi

# записать текущее состояние
if pgrep -f "$SCRIPT" >/dev/null; then
  echo "running" >"$STATEFILE"
else
  echo "stopped" >"$STATEFILE"
fi
