2

I'm running Ubuntu 20.04.5 LTS with the XFCE4 window manager.

I'm looking for a way for a shell script to be fired off when a particular X Window has been closed.

I know that I can create a program to run wmctrl or xdotool over and over again in a loop that checks for the existence of the X Window in question, and then executes a shell script when the presence of that X Window is no longer detected.

But I'm wondering whether there might be some sort of event-based utility that I can run which can do some or all of this for me, instead of my having to write this busy-wait-based program.

Any suggestions?

Thank you in advance.

1 Answer 1

2

A simple way to do this is with the xprop standard X11 utility. You provide a means of identifying the window, by window id, window name, or interactively by clicking on it, and it shows the X11 properties of that window. Adding the option -spy will make it loop waiting for changed-property events, which it will display. This is not a busy loop, but uses the standard X11 mechanism to wait for asked-for events. When the window dies, the event queue gets closed, and xprop ends cleanly. For example,

xterm -title mytest -e 'sleep 5' &
sleep 1
xprop -spy -name mytest
echo "rc=$? xterm done"

Typically, only a few properties ever change, such as when the window is iconised.

1
  • Thank you! This works great! Commented Sep 8, 2022 at 21:46

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.