-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey.py
42 lines (34 loc) · 1.18 KB
/
key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time, os, sys
from threading import Thread
from keyring import get_credential
password = sys.argv[1]
path=os.environ["HOME"]+"/"+"autokeyring"
if not os.path.exists(path):
import tkinter # python3-tk
from tkinter import messagebox
root = tkinter.Tk()
root.withdraw()
messagebox.showwarning('Keyring', 'Call get_credential?')
# Triggers the keyring popup if the keyring is not unlocked already.
# Locks the thread until the popup is closed.
#
# The credentials requested are arbitrary, they are not of interest.
def trigger_keyring_unlock_popup():
try:
#if adding kwallet but still want gnome: in .config/python_keyring/keyringrc.cfg add:
#[backend]
#default-keyring=keyring.backends.SecretService.Keyring
get_credential("service", "login")
except:
print("Keyring unlock popup closed! (cancelled)")
# Create a thread to trigger the keyring unlock popup.
popup = Thread(target = trigger_keyring_unlock_popup)
popup.start()
def is_locked(): return popup.is_alive()
# Wait a moment for the system to react
# Then check if the system is locked or not
time.sleep(3)
if (is_locked()):
os.system("~/test/dotool type " + password)
time.sleep(2)
os.system("~/test/dotool key Enter")