How to emulate pressing the Close button from a script?

I wanted Thunderbird to stay in the Background to notify me of incoming mails.

After a bit of searching, I found this post.
How to keep Thunderbird and Pidgin running on background?

The solution is to install an addon so that when we close Thunderbird it just stays in the background.

Now, to have thunderbird running at Start up we can just add it to Startup Applications.

But, when I open my system, Thunderbird also gets opened and I have to manually press the close button everytime to make Thunderbird go into the background.

The solution given in the above post for this problem is to select Minimize on start. But doing so affects the way in which Thunderbird works when invoked from the Messaging menu. So I deselected this option.

But, if there is a way to emulate pressing the Close button from a script, I can just add that script to Startup Applications

So is there a way to achieve this?

Note : If there is a simpler way to solve my original problem of keeping Thunderbird in background please post that also.

Many thanks.


In the probable absence of a Thunderbird command-line option that you could use to start it minimized or in the background, your best option is probably to use something like xdotool, which is in the repositories. (See my later note on the minimize to tray addon).

This is the command you need to minimise the instance of Thunderbird; xdotool searches for the Thunderbird window on the window stack and then minimizes it

xdotool search --class thunderbird windowminimize %@

Maximise Thunderbird and then try it in the terminal; it seems to be the command you are looking for. Often when used in scripts the --sync argument is added, as noted in the man page:

After requesting the window minimize, wait until the window is actually minimized. This is useful for scripts that depend on actions being completed before moving on.

You may also have to delay the command a bit until Thunderbird has actually started up, and there is a sleep command built into xdotool, so you could use

xdotool sleep 6 search --class thunderbird windowminimize %@

and set the sleep interval at whatever value you needed.

This minimises Thunderbird, but not to the background like when you use the minimize to tray addon, as you set up that addon so that pressing exit sends Thunderbird to the tray. Assuming that addon is installed, it may be possible to use xdotool to emulate the mouse-click of the x in Thunderbird's window and so background it. However, using windowkill instead of windowminimize with Thunderbird (when the tray addon is installed) closes the entire application.


After discussion it was said that the windowunmap option was the one necessary to actually hide the window; this is much easier than trying to emulate a click on the thunderbird window.

xdotool sleep 6 search --class thunderbird windowunmap %@