I've been having some problems with my screenlocker program. Spent a day trying to solve it but nothing worked, so I decided to write a program that locks my screen:
LOCKTIME=60
lastIdleTime=0
extra=0
while [ 1 ]; do
sound=$(pacmd list-sink-inputs | grep -c "state: RUNNING")
idleTime=$(($(xprintidle) / 1000))
lock=$(gnome-screensaver-command -q | grep -c " active")
if [[ $lock != 0 ]]; then
extra=$idleTime
else
if [[ $sound != 0 || $idleTime -lt $lastIdleTime ]]; then
extra=$idleTime
fi
if [[ $(($idleTime - $extra)) -gt $LOCKTIME ]]; then
gnome-screensaver-command -l
fi
fi
lastIdleTime=$idleTime
sleep 1
done
If I execute it manually, everything goes well. But I want to run it at startup, so I tried to use crontab and create a desktop entry at ~/.config/autostart folder. But it seems that crontab doesn't execute the program, or it executes but the script can't lock my screen, and it runs with desktop entry, but xprintidle
doesn't update and gnome-screensaver-command -q | grep -c " active"
returns 0 all the time, so after 60 seconds it stays locking my screen every second.
I also wrote it in python, and it doesn't work either. The only diference is that gnome-screensaver-command -q | grep -c " active"
returns 1 all the time.
Is there a better way to execute and keep it running (and working) every startup?
Btw, I'm using Antergos with GNOME and GDM.