Created
August 9, 2011 16:49
-
-
Save d1b/1134552 to your computer and use it in GitHub Desktop.
python_gnome_unlock_on_usb_device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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