0

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.

  • 1
    If you're using cron to run it at startup, try starting it as your user and not root. – Lukas Isselbächer Jul 16 '17 at 06:57
  • 1
    Also, cron is not using the same environment (X11 display, D-Bus session, etc.) – ephemient Jul 16 '17 at 07:42
  • Call your script via su and make it a login shell. Here is an example of the cronjob entry: `@reboot su - [YOURUSER] -c "[PATHTOYOURSCRIPT] &"` – Lukas Isselbächer Jul 16 '17 at 15:22
  • @LukasIsselbächer I'm already running as my user and I tried your entry at the command line, but pacmd complains that there is no pulse audio daemon running (I think it's because of the flag --login ), and cron didn't execute it either. ephemient I know it, do you think I can do it using a desktop entry? – IceMage144 Jul 16 '17 at 21:33

0 Answers0