I'm using the wmctrl to close running windows when I want shutdown the computer. It's because I need to save workspace in Eclipse and also I don't want to lost my opened tabs in Chrome. I wrote a little script that accomplish the thing, but it's not perfect. Sometimes windows don't close gracefully so I'm loosing my tabs or changes in source code. Is there any way to tell wmctrl wait until the window is closed? My script depends now on 3 seconds sleep (the problematic line), but it's obviously not a good solution.
wmctrl -c chrome
wmctrl -c eclipse
sleep 3
poweroff
You're asking the wrong question. You shouldn't wait until the window has closed, but until the process has died.
Fortunately, that's an easier question to answer.