Skip to content

Instantly share code, notes, and snippets.

@danilin-em
Created December 1, 2019 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilin-em/1d76f409310eeb6967fe1bbefcbc6744 to your computer and use it in GitHub Desktop.
Save danilin-em/1d76f409310eeb6967fe1bbefcbc6744 to your computer and use it in GitHub Desktop.
Lock Screen via DBus (Python)
"""DBus Display Manager Session Lock
@author Evgenii Danilin <evgenii.danilin.m@gmail.com
"""
import dbus # type: ignore
SERVICE_NAME = 'org.freedesktop.DisplayManager'
SERVICE_PATH = '/org/freedesktop/DisplayManager/Session0'
def get_session_iface():
bus = dbus.SystemBus()
proxy = bus.get_object(SERVICE_NAME, SERVICE_PATH)
return dbus.Interface(proxy, dbus_interface=SERVICE_NAME+'.Session')
def lock():
session_iface = get_session_iface()
session_iface.Lock()
def main():
lock()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment