MozillaZine

Start Thunderbird, sync and quit from the command line

User Help for Mozilla Thunderbird
mojo-chan
 
Posts: 128
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: 46341
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: 128
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: 3682
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

Return to Thunderbird Support


Who is online

Users browsing this forum: Google Adsense [Bot] and 3 guests