2

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?

naskoos
  • 379
  • What is the reason for not just killing the thunderbird process gracefully using kill? – gertvdijk Jan 01 '13 at 17:15
  • I want it to be minimized on the tray (message indicator) so that it can check for emails (running on the background)... Currently I'm using a Thunderbird add-on (MinimizedToTray) which does exactly this when you close it pressing the close button... I'm also using "xdotool" to emulate this click from a script.. kill is not an option I've tried it! – naskoos Jan 02 '13 at 01:55
  • In that case, you should rephrase your question imho. You're stating you'd like a script to close Thunderbird. Now you appear you want to minimize windows of the running instance. – gertvdijk Jan 02 '13 at 02:41
  • Maybe you are right I'll rephrase it, but my question is not how to close or how to simulate close or how to minimize the window, I've found that part (using "xdotool")... The actual question is on the title and on the last sentence! Thank you for your interest!! – naskoos Jan 02 '13 at 09:04

2 Answers2

0

I use devilspie2 a great software to control my windows. Attention to the number 2 because there is a different version. I think this is an upgrade to the other.

It has a --debug and a default.lua script that lists all current windows and applications. If you are good at text processing you can match the window title to figure out if it is displayed (this title may change when it is visible). You can also study devilspie2 documentation for other various and powerful options.

Devilspie2 online Manual

A sample of the output running:

 $ devilspie2 ~/.config/devilspie2/default.lua --debug

Application: Thunderbird Window: Pastas Locais - Mozilla Thunderbird Class: thunderbird-esr Application: Thunderbird Window: Pastas Locais - Mozilla Thunderbird Application: Thunderbird Window: Pastas Locais - Mozilla Thunderbird Application: xfdesktop Window: Desktop Class: Xfdesktop Application: xfdesktop Window: Desktop Application: xfdesktop Window: Desktop Application: xfce4-panel Window: xfce4-panel Class: Xfce4-panel

0

Try this:

wmctrl -l | grep -i thunderbird
Adobe
  • 3,981