-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinhibit-screensaver
executable file
·34 lines (29 loc) · 1009 Bytes
/
inhibit-screensaver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
if [[ -z "$1" ]] ; then
printf 'Usage: %s [PID|command]\n' "$0"
printf '\nInhibits the screensaver until PID stops running or the command finishes\n'
exit 1
fi
inhibit_until_killed() {
while sleep 30 ; do
xscreensaver-command -deactivate 2>&1 | grep -v -e '^xscreensaver-command: not active: idle timer reset.$' -e '^$'
printf '.'
done
}
if [[ "$1" =~ ^[0-9]+$ ]] && [[ "$#" == "1" ]] ; then
printf 'Inhibiting screensaver while process %s is running\n' "$1"
while ps $1 >/dev/null ; do
xscreensaver-command -deactivate 2>&1 | grep -v -e '^xscreensaver-command: not active: idle timer reset.$' -e '^$'
printf '.'
sleep 30
done
printf '\nProcess %s is no longer running, stopped inhibiting screensaver\n' "$1"
else
printf 'Inhibiting screensaver until command finishes: '
printf '%q ' "$@"
printf '\n'
coproc inhibit_until_killed
"$@" ; RETURN_CODE=$?
kill ${COPROC_PID[0]}
exit $RETURN_CODE
fi