windowlogger-linux/logger.py
2020-08-01 19:23:25 -03:00

30 lines
596 B
Python

import subprocess
from datetime import datetime
import time
def get_active_window():
return subprocess.run(["xdotool", "getwindowfocus", "getwindowname"], capture_output=True).stdout.decode("utf-8")
def update(title):
with open("logs.txt", "a") as file:
time = datetime.now().timestamp()
newline = '{}, "{}"\n'.format(time, title[:-1])
file.write(newline)
oldwin = get_active_window()
update(oldwin)
while True:
time.sleep(60);
win = get_active_window()
if oldwin != win:
oldwin = win
update(oldwin)
print(oldwin)