1

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 :

name: xfwm4
class: xfwm4
pid: 6981

I just want xfwm4 from name.Is there any alternative of subprocess and wmctrl for showing window manager? This is my code so far,

def getWM():
    try:      
        output = subprocess.run(['wmctrl', '-m'], text=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        if output.stdout:
            s =  (output.stdout) + ' '
        return s
    except:
        return None

1 Answer 1

1

Using split is simplest:

import subprocess as sb
output=sb.run(['wmctrl', '-m'], text=True,stdout=sb.PIPE, stderr=sb.PIPE)
namestr=output.stdout.split('\n')[0]
# For me this gives 'Name: KWin'
name=namestr.split(' ')[1]
# and this gives 'KWin'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.