Skip to content

Instantly share code, notes, and snippets.

@eze-kiel
Created October 19, 2023 09:55
Show Gist options
  • Save eze-kiel/92de81bb43a1fa895b28b26f653cea7d to your computer and use it in GitHub Desktop.
Save eze-kiel/92de81bb43a1fa895b28b26f653cea7d to your computer and use it in GitHub Desktop.
Script to detect activity on the computer (keyboard/mouse)
#!/bin/bash
state="active"
threshold=10000
while true; do
sleep 1
idle=$(xprintidle)
if [[ "$idle" -lt "$threshold" && "$state" != "active" ]] ; then
state="active"
echo "$(date) - new activity started"
continue
fi
if [[ "$idle" -ge "$threshold" && "$state" == "active" ]]; then
state="inactive"
echo "$(date) - stopped activity"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment