В сценарии Bash, как я могу ожидать, пока приложение не открыто?
Пример:
#!/bin/bash
# wait until Thunderbird open to then close its main window...
wmctrl -c "Mozilla Thunderbird"
Основной ответ - то, что необходимо контролировать список открытых окон для изменения. Можно сделать так в количестве путей, но так как Вы используете wmctrl
, можно использовать это как так:
#!/bin/bash
while true
do
# get list of windows
windows=$(wmctrl -l)
# check if window is on the list
if [[ "$windows" =~ "Mozilla Firefox" ]];
then
echo "found firefox, closing it in 3 seconds"
sleep 3
wmctrl -c "Mozilla Firefox"
fi
# delay until next loop iteration
sleep 3
done
, Так как Вы также запросили пример на цикличное выполнение до определенных завершений окна, вот отредактированный пример с альтернативным подходом цикличного выполнения (который был бы, вероятно, предпочтен; по крайней мере это - структура, я лично использую довольно много):
#!/bin/bash
# Script enters into this while loop, and keeps checking
# if wmctrl -l lists firefox. Condition is true if firefox
# isn't there. When firefox appears, condition is false,
# loop exits
while ! [[ "$(wmctrl -l)" =~ "Mozilla Firefox" ]]
do
# number of seconds can be changed for better precision
# but shorter time equals more pressure on CPU
sleep 3
done
# Only after firefox appears , we get to here
echo "found firefox, closing it in 3 seconds"
sleep 3
wmctrl -c "Mozilla Firefox"
# Same idea as before - we enter the waiting loop,
# and keep looping until firefox is not on the list
windows=$(wmctrl -l)
while [[ "$(wmctrl -l)" =~ "Mozilla Firefox" ]]
do
sleep 3
done
#When loop exits, that means firefox isn't on the list
echo "Script is done"