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?
Start Thunderbird, sync and quit from the command line
-
- Posts: 131
- Joined: November 25th, 2003, 8:56 am
- tanstaafl
- Moderator
- Posts: 49647
- Joined: July 30th, 2003, 5:06 pm
Re: Start Thunderbird, sync and quit from the command line
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.
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.
-
- Posts: 131
- Joined: November 25th, 2003, 8:56 am
Re: Start Thunderbird, sync and quit from the command line
Thanks, that's a good idea. If I just let it run for several hours overnight it should sync.
-
- Posts: 6404
- Joined: February 3rd, 2009, 6:29 pm
Re: Start Thunderbird, sync and quit from the command line
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: http://forums.mozillazine.org/viewtopic ... #p14166149
nsICommandLineHandler example
http://forums.mozillazine.org/viewtopic ... &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.readth ... egacy.html
Reference
http://nircmd.nirsoft.net/closeprocess.html
http://nircmd.nirsoft.net/killprocess.html
More info: http://forums.mozillazine.org/viewtopic ... #p14166149
nsICommandLineHandler example
http://forums.mozillazine.org/viewtopic ... &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.readth ... egacy.html
-
- Posts: 131
- Joined: November 25th, 2003, 8:56 am
Re: Start Thunderbird, sync and quit from the command line
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?
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?
-
- Posts: 131
- Joined: November 25th, 2003, 8:56 am
Re: Start Thunderbird, sync and quit from the command line
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.
taskkill /im thunderbird.exe
That sends the same WM_CLOSE message to the TB main window so does a graceful shutdown.
-
- Posts: 6404
- Joined: February 3rd, 2009, 6:29 pm
Re: Start Thunderbird, sync and quit from the command line
Hmm, that works on Windows 10.
I got the "Do you want to save changes to Untitled?" prompt with the first command.
Not sure that works on Windows 7.
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
Not sure that works on Windows 7.
-
- Posts: 131
- Joined: November 25th, 2003, 8:56 am
Re: Start Thunderbird, sync and quit from the command line
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.
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.