Show a dialog box after a period of inactivity

I am soon going to have to migrate an entire computer lab (about 50 PCs) from Windows 7 to Ubuntu 14.04 LTS. As it's an university, 99% of the time (if not 100%) it will be used by students. There is not a central database of user accounts and credentials, so each PC will have only two accounts, admin and guest, with the latter configured to autologin (besides some customization as per this tutorial).

When the PCs are turned on, and the guest account logs in automaticcaly, the first thing shown after the window manager is loaded is this dialog box:

enter image description here

However, there's two problems:

  1. The very first person who sits at the computer at 9am will see the dialog box, click OK, use the PC, leave, not ending the session or locking the screen (because users), and the second user onwards won't see the message
  2. There is more relevant information that I'd like to convey for the lab users (lab rules, etc).

So, with this scenario in mind, what I want to achieve is having a dialog box really similar to this one (but with a different text, set by me) to popup whenever a computer isn't used for, say, 15 minutes. (For the purpose of this question, let's assume "not used" means no keyboard or mouse activity).

I have been directed to How does ubuntu determine inactivity before suspending? and How can a script detect a user's idle time? and use ruby or sheel scripts, but I don't know how to code.

Is there a simpler way to achieve what I need?


Solution 1:

Use xautolock

xautolock -time 15 -locker notify-send -t time "Title" "message_here" -i "path/to/icon"

or use zenity or any dialog you wish.

See http://manpages.ubuntu.com/manpages/trusty/man1/xautolock.1.html

Edit: After the edit to the question, the OP went with zenity

xautolock -time 15 -locker "zenity --text='<text here>' --warning"

Solution 2:

If you run the following script in the background, it will check the idle-time every 5 seconds. If the idle time exceeds a given amount of time (in minutes), a message will appear, defined in a textfile. (through a Zenity window).

#!/usr/bin/env python3

import subprocess
import time
#########################################
t=15
textfile = "/path/to/message_textfile"
#########################################

with open(textfile, "r") as text:
    message = text.read()

while 1!=0:
    get_idle = subprocess.Popen(["xprintidle"], stdout=subprocess.PIPE)
    result = get_idle.communicate()[0].decode("utf-8")
    if int(result)/60000>t:
        if warning_given == "yes":
            pass
        else:   
            subprocess.Popen(["zenity", "--warning",  "--no-wrap", "--text="+message,  ])
            warning_given = "yes"
    else:
        warning_given = "no"

    time.sleep(5)

enter image description here

How to use

  • install xprintidle:

    sudo apt-get install xprintidle
    
  • Copy the script into an empty file, set the idle time (t) in minutes and set the path to the textfile containing your message text. Save it as set_warning.py

  • Run it by the command

    python3 /path/to/set_warning.py
    

Notes

  • For convenience reasons (and to have control over the text layout), the text is taken from an external textfile. Returns etc. will be copied exactly from the text file into your message. Since the --no-wrap option from zenity is used, you need to use the returns, or otherwise your message will be excessively broad.
  • The way the message appears can be "tweaked" with other zenity options.

Solution 3:

Here's what I ended up doing:

xautolock -time 15 -locker "zenity --text='<text here>' --warning"

I added that line as an entry on the session apps of the account that is soft linked to /etc/guest-session/skel, so it will run every time the guest session starts.