4

One of my elderly parents (late 80s) has dementia and becomes obsessed with one or two games. (Aisleriot Solitaire and Mahjong). They become fixated on it and will play for hours. (Fine, it is their life.) However, we want to start monitoring it making them aware that they are doing this.

Is there some parental control software or similar which would enable us to have a quota of time for a particular application and then once the quota has passed for the day would pop up a dialog window noting the total time they've played that day every 30 minutes thereafter?

I don't want to completely lock screen or anything (safety concerns) and don't want to stop play (insultingly infantilizing), just have them have to click Ok on a popup window showing total time or something (if previous window has been dismissed obviously, in case they've just left the game up). Even better if we can control the message.

I know the timelimit script could limit run time but that doesn't really have the other aspects.

Any suggestions for something that does this or better solutions that aren't too infantilizing?

[Edit: The suggested parental control apps do not provide the functionality suggested above (and some don't run in current Ubuntu 22.04 and 24.04). The suggested timer-applet does not provide the necessary functionality, nor do various alarm solutions which are likely to confuse the elderly person in question. I am many thousands of miles distant from the computer in question, and just want a pop up reminder of how long they've been playing that one specific game total that day with the conditions outlined above. We do not want to distress the parent. (I would also note that as the ubuntu-using population ages into their late 80s and above, this kind of thing may become a more common question.)]

JamesC
  • 121
  • 1
  • 5

2 Answers2

3

I tested this in Ubuntu 24.04 and Mahjong.

You need to create two files. First is a bash script that will start the timer and call Mahjong. Second is the desktop launcher that will allow you to create a shortcut of the game Mahjong so that it starts with the script rather than directly.

1. The Script

This script uses zenity. Zenity is installed by default in Ubuntu 24.04. if it is not installed, use the command:

sudo apt install zenity

The script assumes your computer has the deb version of mahjong installed. If you have the snap version, the script won't not work.

Copy and paste the script below in the bin folder of the user's home with the name /home/username/bin/my_mahjongg, where username is your or your parent's user name.

#!/bin/bash
# Date: Oct 4, 2024
# Purpose: A wrapper script to show a pop up at an interval while playing Mahjongg

If the Mahjongg.desktop does not exist, create it based on the default launcher

then delete lines with local languages and replace the name of the executable with

the name of this script

if [[ ! -f $HOME/.local/share/applications/Mahjongg.desktop ]]; then echo personlized launcher file does not exit, creting one... cp /usr/share/applications/org.gnome.Mahjongg.desktop $HOME/.local/share/applications/Mahjongg.desktop sed -i -e /"["/d -e s,Exec=gnome-mahjongg,Exec="$HOME/bin/""$(basename "$0")",g -e s/"Name=Mahjongg"/"Name=My Mahjongg"/g $HOME/.local/share/applications/Mahjongg.desktop sed -i '1s/^/[Desktop Entry]\n/' $HOME/.local/share/applications/Mahjongg.desktop fi

End of launcher file createion

SECONDS=0 # Initializing builtin seconds counter pop_sec=300 # First pop up in seconds (1 hr = 3600 sec) pop_sec2=$((pop_sec/2)) # Subsequent pop up in half the time of first pop up

(/usr/games/gnome-mahjongg &) # Starting Mahjongg while (pidof gnome-mahjongg >/dev/null 2>&1) # While Mahjongg is running do if [[ $SECONDS -ge $pop_sec ]]; then # check if it is time for a reminder hr_min=$(printf '%dh:%dm\n' $((SECONDS/3600)) $((SECONDS%3600/60))) zenity
--info
--text="<span size=&quot;xx-large&quot;>You have played Mahjongg for $hr_min.</span>\n\nIt is time for a <b>break</b>. Close the game now.\n\n If you don't stop, I will remind again in $((pop_sec2/60)) minutes"
--title="Reminder"
--ok-label="OK, I will stop now!" --timeout=30 pop_sec=$((SECONDS+pop_sec2)) fi sleep 30s # wait time before checking again if Mahjongg is running done

Modify the script

The script a variable pop_sec=300 This is the number of seconds the script will run before the first reminder pop up. I have set 300 seconds = 5 minutes for testing. You may want to set it to 3600, that is, 1 hour. Subsequent reminders will pop up half the time of the initial reminder.

Enable logging

Add the following line at the bottom of the script if you want to log the time you spend on each session of Mahjong.

echo "Mahjong was open for $(printf '%dh:%dm\n' $((SECONDS/3600)) $((SECONDS%3600/60))) on $(date)" >> $HOME/My_Mahjongg.log

This of code line will add a line to the log file My_Mahjongg.log in the user's home folder every time Majongg is played. An example:

Mahjong was open for 1h:23m on Sat Oct  5 09:35:30 AM EDT 2024

Make the script executable

A script needs to be executable before you can run it.

Either

right click on the script and select Properties. In the next window, turn on the switch Executable as a program

Or

use the command:

chmod +x bin/my_mahjongg

You don't have to do both.

Try the script

Now you can start the script from the terminal by entering:

my_mahjongg

This will start the script in the background and open Mahjong. After one hour a reminder window will pop up.

enter image description here

You will be able to dismiss the window by clicking on the OK button at the bottom of the window. Clicking this button won't close Mahjong. If you don't click the button the reminder will close it self in 30 seconds.

If you close Mahjong, the script will exit. If you continue to play the reminder will pop up again in half an hour.

First run creates a desktop launcher

The first time you run the script, it will look for a corresponding desktop launcher file /home/username/.local/share/applications/Mahjongg.desktop. If this file does not exist, the script will create this launcher file based on the default Mahjongg desktop launcher.

If all goes well you will see 2 Mahjong icons when you search for the game to play. The first will say "Mahjong". This is the standard one. The second will say "My Mahjong" this will start the script which will start Mahjong.

2. Create a shortcut on Dash

Dash is the vertical bar on the left side of Ubuntu desktop with icons of apps that can be launched. You may want to create a shortcut of "My Mahjong" on the Dash so that you or your parent can start the game by clicking on it.

Search for the app "my Mahjong" and drag and drop in on the dock.

enter image description here

Some Caveats

I have set up the script and the launcher file in one user's personal "Home" folders. The user can change, or remove these files. If each of your parents have separate user accounts, and you want to set it up for all (both) the users, you would keep the files in a different more global location. This will make it harder for the users to remove or modify the files without sudo.

The script is more of a demonstration of a concept rather than a finished product. It works on my computer, but yours may be different. I would like to know if you have any problems with it, but I can't guarantee a fix.

To Do

Currently the timer stops once you close Mahjong. I could save the cumulative play-time for the day in a file and use it in the reminder. For example, if one plays Mahjong for 4 hours in 1 hour sittings each, the script could keep track of that. This will add more complexity to the script.

Hope this helps

user68186
  • 37,461
1

+1 for: "I would also note that as the ubuntu-using population ages into their late 80s and above, this kind of thing may become a more common question."

Longshot, but considering they are just focused on one or two games, maybe something like this (screen time vs. app time) would work just as well and would still work if they shifted focus to other games: break-reminder-for-ubuntu

Noted you are many thousands of miles away, but are you or another family member in touch with their health care provider? They may have suggestions (perhaps as simple as an hour glass, and may be able to advise on how serious the consequences of this behavior are.