I need to implement a function that monitors the screen lock/unlock. I referred to the following article:
Run script on screen lock/unlock
My python script code works fine in Ubuntu 12.04, but it doesn't work in Ubuntu 14.04:
#!/usr/bin/env python
import gobject
import dbus
from dbus.mainloop.glib import DBusGMainLoop
def filter_cb(bus, message):
if message.get_member() != "ActiveChanged":
return
args = message.get_args_list()
if args[0] == True:
print("Lock Screen")
else:
print("Unlock Screen")
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string("type='signal',interface='org.gnome.ScreenSaver'")
bus.add_message_filter(filter_cb)
mainloop = gobject.MainLoop()
mainloop.run()
I also tried the command:
dbus-monitor --session "interface='org.gnome.ScreenSaver'"
It outputs nothing when I lock/unlock the screen manually.
How can I monitor the screen lock/unlock in the Ubuntu 14.04?