4

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?

2

3 Answers 3

5

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"
4
  • Looking at the edited question, I don't think the OP was looking for a notify-send solution.
    – Seth
    Aug 15, 2014 at 4:30
  • Yeah, but zenity provides me what I need Aug 15, 2014 at 14:36
  • @Seth - Thank yor for the heads up. One can call zenity or any other dialog/notification they so desire from xautolock -locker ....
    – Panther
    Aug 15, 2014 at 15:05
  • Yup, saw that. I just figured you might want to update your answer after the OP edited his question.
    – Seth
    Aug 15, 2014 at 15:19
3

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.
1
  • 2
    +1 for 'If your teacher asks for coffee, bring it to him or her right away' :-)
    – Parto
    Aug 15, 2014 at 10:20
1

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.

4
  • 1. I'm not sure if it's bad practice Aug 15, 2014 at 14:36
  • 2. How do I make the --text parameter read the text from a file? Aug 15, 2014 at 14:37
  • 2
    2: Try $(cat someTextFile) in place of raw text.
    – Seth
    Aug 15, 2014 at 15:21
  • 1
    @Seth actually it's \"$(cat someTextFile)\" (thanks to @ EliahKagan in the chat room) Aug 15, 2014 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .