I’m the proud father of 2 teenagers, and I’d like to know if it’s possible to set screen time limits according to the user (e.g.: login only allowed between 7am and 8pm, with a limit of 1 hour/day on weekdays and 2 hours on weekends).
And the script doing the work /usr/local/bin/timer.sh
#!/bin/bash
# Session duration 600 cycles (seconds)
MAX=600
TIMER=$MAX
# Show a warning when 10 cycles (seconds) remaining
WARNING=10
COUNT=0
# Show a notification every 60 cycles (seconds)
NOTIFICATIONINTERVAL=60
zenity --warning --text="The session will last $TIMER seconds" --timeout=5 &
while [ $TIMER -gt 0 ]
do
let TIMER=$TIMER-1
let COUNT=$COUNT+1
if [ $COUNT -eq $NOTIFICATIONINTERVAL ]
then
if [ $TIMER -eq $WARNING ]
then
zenity --warning --text="Only $TIMER seconds left" --timeout=10 &
else
zenity --notification --text="$TIMER seconds left"
fi
COUNT=0
fi
sleep 1
done
gnome-session-quit --logout --force --no-prompt
The script forces the logout after 5 minutes, it displays a notification every 60 seconds, and a dialog when there are 10 seconds left (and an initial dialog which warns how long the session will last).
In order to avoid unwanted modifications, sudo chown youruser:youruser /usr/local/bin/timer.sh /home/childuser/.config/autostart/timer.desktop
Ok, I’m not very well-versed in math neither in bash scripting, but this could be a good start if you will not find something better and more solid.