-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (27 loc) · 890 Bytes
/
main.py
File metadata and controls
33 lines (27 loc) · 890 Bytes
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
import os
import subprocess
import time
from datetime import datetime
log_file_path = os.path.expanduser("~/.log_primary/log_primary.txt")
os.makedirs(os.path.dirname(log_file_path), exist_ok=True)
def get_primary_selection():
try:
result = subprocess.run(
["xclip", "-o", "-selection", "primary"],
capture_output=True,
text=True
)
text = result.stdout.strip()
return text
except Exception:
return ""
last_selection = None
while (True):
latest_selection = get_primary_selection()
timestamp = datetime.now().strftime("[%Y-%m-%d %H:%M:%S]")
if (latest_selection != last_selection):
last_selection = latest_selection
stamp = f"{timestamp} {latest_selection}"
with open(log_file_path, "ab") as f:
f.write((stamp + "\n").encode("utf-8"))
time.sleep(0.1)