0

I would like my children to only use the computer for 30 minutes, at which time I would like the screen to be locked. At that point, if I choose to unlock the screen again, I would like the screen to lock again in another 30 minutes.

How can I write a script to do this?

To lock the screen from the command line (on ubuntu), I can use the command

gnome-screensaver-command -l

but how do I activate this command 30 minutes after unlock?

aam
  • 1

1 Answers1

0

Thank you for the comment, which helps. Here is the solution I came up with, in python 2.x:

import gobject, dbus, time, subprocess
from dbus.mainloop.glib import DBusGMainLoop  

time.sleep(30*60)
subprocess.Popen(["gnome-screensaver-command", "-l"])

def lock_status(bus, message):

    if message.get_member() != "EventEmitted": 
        return

    args = message.get_args_list()

    if args[0] == "desktop-unlock":  
        time.sleep(30*60)
        subprocess.Popen(["gnome-screensaver-command", "-l"])

DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string("type='signal',interface='com.ubuntu.Upstart0_6'")
bus.add_message_filter(lock_status)
gobject.MainLoop().run()
aam
  • 1