I have the following code to check whether the screen is locked or not (using gnome-screensaver)
gnome-screensaver-command -q | grep "is active"
From this link, https://askubuntu.com/questions/17679/how-can-i-put-the-display-to-sleep-on-screen-lock there is a code on using it on a shell script. But how do I use the code in python? And store it in a varaiable whether if it is active or not.
import dbus
This catches all screensavers, not just Gnome. It also doesn't block by using something like
You can also talk to the gnome-screensaver via D-Bus:
You can execute the shell command in Python using
subprocess
, and then grep its stdout foris active
line: