I'm trying to write a shell script that recognizes if Thunderbird window is displayed and if so it disposes it to the messages tray.
I'd like to use it in this answer of "How to keep Thunderbird and Pidgin running on background?" question.
So far I'm using the "xdotool" to check if Thunderbird is displayed and simulate close on it as suggested in "How to emulate pressing the Close button from a script?".
#!bin/bash
thunderbird &
TB=$(xdotool search --class thunderbird)
while [ -z "$TB" ]; do
sleep 2
TB=$(xdotool search --class thunderbird)
done
xdotool search --class thunderbird windowunmap %@
But xdotool search --class thunderbird
returns result by the time Thunderbird is launched, before is actually displayed, so xdotool search --class thunderbird windowunmap %@
waits for ever doing nothing.
To bypass this limitation a sleep xx
is added in the actual command, but the sleep time needed, defers from system to system.
I've also used "xwininfo" to check if Thunderbird is displayed but it behaves the same as "xdotool", so I had to add sleep xx
here too.
#!bin/bash
thunderbird &
t="Thunderbird"
stop=0
xwininfo -name $t > /dev/null 2>&1
if [ $? -eq 0 ]; then
stop=1
fi
while [ $stop -eq 0 ]; do
xwininfo -name $t > /dev/null 2>&1
if [ $? -eq 0 ]; then
stop=1
fi
done
sleep 2
xdotool search --class thunderbird windowunmap %@
Is there any other way to check for "really" displayed windows?
Try this: