Skip to content

Instantly share code, notes, and snippets.

@d1b
Created August 9, 2011 16:49
Show Gist options
  • Save d1b/1134552 to your computer and use it in GitHub Desktop.
Save d1b/1134552 to your computer and use it in GitHub Desktop.
python_gnome_unlock_on_usb_device
import time
import subprocess
def is_screen_locked():
output = subprocess.Popen(["gnome-screensaver-command", "--query"], stdout=subprocess.PIPE).communicate()[0]
if "screensaver is inactive" in output:
return False
return True
def monitor_and_unlock(usb_id):
while True:
if is_screen_locked():
output = subprocess.Popen(["lsusb"], stdout=subprocess.PIPE).communicate()[0]
for line in output.split("\n"):
if usb_id in line:
print "%s:unlocking!" % time.time()
subprocess.Popen(["gnome-screensaver-command", "-d"])
time.sleep(5)
if __name__=="__main__":
usb_id = ""
monitor_and_unlock(usb_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment