-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathact.py
More file actions
executable file
·38 lines (34 loc) · 1.1 KB
/
act.py
File metadata and controls
executable file
·38 lines (34 loc) · 1.1 KB
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
#!/usr/bin/python
import subprocess
import re
import time
def get_active_window_title():
root_check = ''
root = subprocess.Popen(['xprop', '-root'], stdout=subprocess.PIPE)
if root.stdout != root_check:
root_check = root.stdout
for i in root.stdout:
if '_NET_ACTIVE_WINDOW(WINDOW):' in i:
id_ = i.split()[4]
id_w = subprocess.Popen(['xprop', '-id', id_], stdout=subprocess.PIPE)
id_w.wait()
buff = []
for j in id_w.stdout:
buff.append(j)
for line in buff:
match = re.match("WM_NAME\((?P<type>.+)\) = (?P<name>.+)", line)
if match != None:
type = match.group("type")
if type == "STRING" or type == "COMPOUND_TEXT":
return match.group("name")
return "Active window not found"
oldtime=time.time()
oldtitle=''
while (1):
curtitle=get_active_window_title()
curtime=time.time()
if curtitle != oldtitle:
print oldtitle, curtime - oldtime
oldtime=curtime
oldtitle=curtitle
time.sleep(1)