I want to check which window manager is active using python? I used subprocess.run but it’s giving me string type output like below :
JavaScript
x
4
1
name: xfwm4
2
class: xfwm4
3
pid: 6981
4
I just want xfwm4 from name.Is there any alternative of subprocess and wmctrl for showing window manager? This is my code so far,
JavaScript
1
9
1
def getWM():
2
try:
3
output = subprocess.run(['wmctrl', '-m'], text=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4
if output.stdout:
5
s = (output.stdout) + ' '
6
return s
7
except:
8
return None
9
Advertisement
Answer
Using split
is simplest:
JavaScript
1
7
1
import subprocess as sb
2
output=sb.run(['wmctrl', '-m'], text=True,stdout=sb.PIPE, stderr=sb.PIPE)
3
namestr=output.stdout.split('n')[0]
4
# For me this gives 'Name: KWin'
5
name=namestr.split(' ')[1]
6
# and this gives 'KWin'
7