This is an old question but this is the best option:
Set your user for automatic login
echo "AutomaticLoginEnable=True" | sudo tee -a /etc/gdm3/custom.conf
echo "AutomaticLogin=$(whoami)" | sudo tee -a /etc/gdm3/custom.conf
Or change in Settings
-> Users
-> Automatic Login
Write a script
gnome-screensaver
can do the job but we have to make shure its available when the machine runs the code. To get it, create a script with the following:
#!/bin/bash
duration()
{
echo "$(( SECONDS - start ))"
}
iscrazy()
{
(( $(duration) > 60 ))
}
state()
{
/usr/bin/gnome-screensaver-command -q
}
isactive()
{
! grep -q "inactive" <<< "$(state)"
}
start=$SECONDS
/usr/bin/gnome-screensaver &
until isactive || iscrazy
do
/usr/bin/gnome-screensaver-command -l
done
echo "$(state) and it took $(duration) seconds"
This will attempt to lock the screen until it succeeds or spends more time than usual.
Make shure that execution is enabled on file permissions with
chmod +x <pathtoscript>
or checking "Allow executing file as program" by right-clicking and going to Properties
-> Permissions
I recommend you run it before the next step
Place it between the startup applications
echo "[Desktop Entry]
Type=Application
Name=Lock Screensaver
Exec=<pathtoscript>" > ~/.config/autostart/screen_lock.desktop
or add manually in "Startup Applications" (gnome-session-properties
)
Notes
Works with Ubuntu and has been tested on a Pop! _OS 20.04
You have to install the needed packages as gnome-screensaver
Remember to change <pathtoscript>
with the path to the script you created