xdotool search --sync --pid "$PID"
fará exatamente o que você deseja. Eu encontrei este método aqui
--sync - Block until there are results. This is useful when you are launching an application and want to wait until the application window is visible.
Modelo:
#!/bin/bash
geany &
PID=$!
if xdotool search --sync --pid "$PID" > /dev/null; then
# if window with the specific PID has appeared
# then doing something here
fi
Nota:
Não funciona com alguns aplicativos, Netbeans
por exemplo, por causa disso:
--pid PID - Match windows that belong to a specific process id. This may not work for some X applications that do not set this metadata on its windows.
Se alterar --pid "$PID"
para --name netbeans
ou --class netbeans
, também funciona.
Exemplo de trabalho:
Este script calcula o atraso em milissegundos, entre o lançamento de geany &
e a janela do geany.
#!/bin/bash
geany &
PID=$!
time_start=$(date '+%s%3N')
if xdotool search --sync --pid "$PID" > /dev/null; then
time_end=$(date '+%s%3N')
time_interval=$((time_end - time_start))
printf "%'d ms\n" "$time_interval"
fi
Saída:
$ ./delay_calculate.sh
553 ms