If I run these commands:...geany --new-instance --no-msgwin --no-session --no-terminal -c pathtoconfig/ &pid=$!echo $pidwmctrl -lpread -p waiting......the resulting PID does not match that of the geany process launched. But if a sleep 1 command is inserted before reading the PID (after the geany line), then the PID is correct. The reason for this is that windowing takes some time, so wmctrl -lp provides preliminary information which does not much precisely the right PID.What would be the best way to wait for geany to complete launching before the new window has stabilized and wmctrl is aware of it?Update:- Run on Lubuntu 16.04 / HP ProBook 6360b.Actual PID for comparison was obtained with wmctrl -lp that includes PID in the list.PID is fetched correctly by $!, what takes some time to update is the one provided by wmctrl -lp, that is different after some time (some 0.27s for geany, some 0.16s for leafpad), as if the window manager would take some time to update the PID.
Background process raising window information with some delay, how to manage it?
process;background process
xdotool search --sync --pid $PID will do exactly, what you want. I found this method here--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.Template:#!/bin/bashgeany &PID=$!if xdotool search --sync --pid $PID > /dev/null; then     # if window with the specific PID has appeared     # then doing something herefiNote:Doesn't work with some applications, Netbeans for example, because of this:--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.If change --pid $PID to --name netbeans or --class netbeans it works too.Working example:This script calculate delay in milliseconds, between launching geany & and the geany's window appearing.#!/bin/bashgeany &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_intervalfiOutput:$ ./delay_calculate.sh 553 ms