Skip to content

Instantly share code, notes, and snippets.

@egdoc
Created February 28, 2019 14:05
Show Gist options
  • Select an option

  • Save egdoc/31dea6203b349038cf4c772175d4d289 to your computer and use it in GitHub Desktop.

Select an option

Save egdoc/31dea6203b349038cf4c772175d4d289 to your computer and use it in GitHub Desktop.
Use python and dbus logind API to lock the screen on suspension with i3lock
#!/usr/bin/env python3
# Basic example of how to use i3lock to lock the screen when system goes to sleep
import subprocess
from pydbus import SystemBus
from gi.repository import GLib
def onSuspend(value):
# When suspending or hibernating the system, "value" will be True
if value:
subprocess.call(['i3lock', '-c', '000000'])
def main():
bus = SystemBus()
logind = bus.get('org.freedesktop.login1', '/org/freedesktop/login1')
logind.PrepareForSleep.connect(onSuspend)
loop = GLib.MainLoop()
loop.run()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment