Pregunta

 xprop | grep WM_CLASS\(STRING\) 

After typing that into a terminal, I have to click onto a window to get a result.

I want to automatize this. I'd like to get the WM_NAME-Window name at a named position, say, x=10 and y=40 (BFB).

xprop | grep WM_NAME\(STRING\) 
sleep(1)
xdotool mousemove 10 40 click 1

Each command on its own is working, but not all together. How can I put this into a script that executes all commands?

¿Fue útil?

Solución

The problem is that xprop is blocking for the mouse click so it needs to be done in the background. The wait is not strictly necessary, but makes the script exit more cleanly by waiting for xprop to complete.

#!/bin/bash
xprop | grep WM_NAME\(STRING\) &
pid=!$
sleep 1
xdotool mousemove 10 40 click 1
wait $pid

Otros consejos

To get that in python code, if someone else is interested:

import subprocess as s

p=s.Popen(["xprop", "WM_NAME"], stdout=s.PIPE)
r=s.Popen(["xdotool", "mousemove", "10", "40", "click", "1", "mousemove", "restore"], stdout=s.PIPE)

out, err = p.communicate()
print(out)

If you want to adjust the output slightly, type "WM_CLASS".

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top