Skip to content

Instantly share code, notes, and snippets.

@guitarmanvt
Last active May 7, 2017 22:13
Show Gist options
  • Save guitarmanvt/6bd807d2926db518d059 to your computer and use it in GitHub Desktop.
Save guitarmanvt/6bd807d2926db518d059 to your computer and use it in GitHub Desktop.
Easy timed turns on Linux for kids (automatic logout after timer ends, with 1-minute warning)
#!/bin/bash
# Requires:
# 1. at
# 2. espeak or spd-say
# 3. zenity
# 4. notify-send
# 5. MATE or Gnome desktop
talk=$(which espeak || which spd-say)
if [[ "$(which mate-session-save)" != "" ]]; then
logout="mate-session-save --force-logout"
else
if [[ "$(which gnome-session-quit)" != "" ]]; then
logout="gnome-session-quit --no-prompt"
else
echo "Unknown desktop error."
return 1
fi
fi
# DEBUG
#logout=$talk' "I just logged you out. Ha ha."'
$talk "How many minutes is your turn?"
end=$(zenity --list --title="How long is your turn?" \
--column="How many minutes is your turn?" \
--width=500 \
--height=250 \
--timeout=30 \
1 \
5 \
10 \
20 \
30)
if [ "$end" == "" ]; then
# It timed out or the user canceled.
echo $talk' "Boop boop beep." && '$logout | at now
else
# Calculate warning time.
warn=$[$end-1]
echo 'notify-send "1 minute left" "Please save your work now." && '$talk' "One minute warning"' | at now + $warn minutes
echo $talk' "Your time is up. Goodbye." && '$logout | at now + $end minutes
$talk "You have '$end' minutes, starting now."
fi
# Done!
@guitarmanvt
Copy link
Author

Add this script to your Startup Items on your kids' user account(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment