MozillaZine


Start Thunderbird, sync and quit from the command line

User Help for Mozilla Thunderbird
mojo-chan
 
Posts: 131
Joined: November 25th, 2003, 8:56 am

Post Posted November 14th, 2019, 12:48 pm

I want to be able to script Thunderbird starting up, syncing email and then quitting. I want it to happen overnight when I'm not using the computer via Task Scheduler, basically as a backup of an IMAP account.

Is there a way to do it?

tanstaafl
Moderator

User avatar
 
Posts: 48199
Joined: July 30th, 2003, 5:06 pm

Post Posted November 14th, 2019, 2:45 pm

The problem is automating Thunderbird quitting

See https://www.howtogeek.com/123393/how-to ... scheduler/ . The Advanced Task Settings section talks about how to modify the tasks properties to end the task after a fixed amount of time. https://www.windowscentral.com/how-crea ... windows-10 is a similar writeup. However, I suspect it doesn't give you fine enough control over how long the task runs, and you would be better off writing a short PowerShell script to launch Thunderbird, and have the task scheduler run that PowerScript.

https://blog.ipswitch.com/creating-a-ti ... ll-scripts talks about how to create a time out in PowerShell scripts. Later on you might find a cleaner/better way to shutdown Thunderbird. I suspect you will need to have the PowerShell script delete the parent.lock temporary file created by Thunderbird in its profile, after it stops Thunderbird. Otherwise you might have problems when you manually launch Thunderbird later on and it checks for the existence of that file, finds it and refuses to launch as it thinks another instance is still running.

https://www.howtogeek.com/137803/geek-s ... owershell/
https://www.techrepublic.com/article/po ... ons-guide/
https://www.pluralsight.com/blog/it-ops ... -execution
http://kb.mozillazine.org/Profile_in_use

One alternative might be to have the task scheduler launch Thunderbird and then a couple of minutes later have another task run a AudoIt or AutoHotKey script to cleanly exit Thunderbird (it could select file -> exit). That would avoid you having to learn PowerShell.

When you get something working please post a writeup of what you did to help somebody else who might want to do the same thing.

mojo-chan
 
Posts: 131
Joined: November 25th, 2003, 8:56 am

Post Posted November 14th, 2019, 2:54 pm

Thanks, that's a good idea. If I just let it run for several hours overnight it should sync.

morat
 
Posts: 4856
Joined: February 3rd, 2009, 6:29 pm

Post Posted November 14th, 2019, 3:26 pm

You can politely close the thunderbird.exe process with NirCmd closeprocess.

Reference
http://nircmd.nirsoft.net/closeprocess.html
http://nircmd.nirsoft.net/killprocess.html

More info: viewtopic.php?p=14166149#p14166149

nsICommandLineHandler example
http://forums.mozillazine.org/viewtopic.php?f=19&t=3021875

In Thunderbird 68...

* create manifest.json file
* replace XPCOMUtils.generateQI with ChromeUtils.generateQI in commandline.js file
* replace MailOfflineMgr.toggleOfflineStatus with goQuitApplication in commandline.js file

More info
http://developer.thunderbird.net/add-ons/tb68
http://thunderbird-webextensions.readthedocs.io/en/68/legacy.html

mojo-chan
 
Posts: 131
Joined: November 25th, 2003, 8:56 am

Post Posted October 14th, 2021, 1:31 am

I recently updated to TB 91 and this stopped working.

It looks like the issue is that if you do "nircmd closeprocess thunderbird.exe" there are actually 3 "thunderbird.exe" processes and it operates on the wrong one. If you specify the PID it works, but of course the PID changes every time TB is launched.

I tried everything I could think of. Closing "ThunderbirdPortable.exe", full path etc. Any ideas?

mojo-chan
 
Posts: 131
Joined: November 25th, 2003, 8:56 am

Post Posted October 14th, 2021, 1:41 am

Okay, I found that the following works:

taskkill /im thunderbird.exe

That sends the same WM_CLOSE message to the TB main window so does a graceful shutdown.

morat
 
Posts: 4856
Joined: February 3rd, 2009, 6:29 pm

Post Posted October 14th, 2021, 3:35 am

Hmm, that works on Windows 10.

Code: Select all
rem send WM_CLOSE message
taskkill /im notepad.exe

Code: Select all
rem send WM_QUIT message
taskkill /f /im notepad.exe

I got the "Do you want to save changes to Untitled?" prompt with the first command.

Not sure that works on Windows 7.

mojo-chan
 
Posts: 131
Joined: November 25th, 2003, 8:56 am

Post Posted October 14th, 2021, 4:44 am

I don't use the /f flag, I think you have to send WM_CLOSE to be safe.

I don't get the save changed prompt. I'm not sure if I turned it off years ago or what, but I don't see it when using that command or clicking the close button myself.

I'm on Windows 8.1.

Return to Thunderbird Support


Who is online

Users browsing this forum: No registered users and 8 guests