Paul - The Programmer

simple & stupid

Lock screen with xscreensaver by Gnome menu 'System / Lock Screen'

First of all, the xscreensaver should be installed and replace the default gnome-screensaver.

You may follow the instructions from the post :

Then, to recover the menu 'System / Lock Screen',  the dbus object org.gnome.ScreenSaver should be created.

I use the below python script to create the org.gnome.ScreenSaver.


import dbus
import dbus.service
import dbus.glib
import gobject
import os

class ScreenDbusObj(dbus.service.Object):
    def __init__(self):
        session_bus = dbus.SessionBus()
        dbus.service.Object.__init__(self,bus_name, '/org/gnome/ScreenSaver')

    def Lock(self):
        os.system( "xscreensaver-command -lock" )

if __name__ == '__main__':

Keep this script running on the background. The 'Lock Screen' button will call the method Lock and the method Lock will execute the xscreensaver-command -lock.

To automatically start this script, add the command,

i.e. /path-to-the-script/ &

in the System/Preferences/Sessions.