Speed up Mail--Keep Envelope Index clean

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Speed up Mail--Keep Envelope Index clean Sat Jun 21, 2008 10:31 pm • by jayhawkbabe
Mail uses sqlite3 in its backend to keep a database of all the messages it contains. When messages are deleted, outdated entries can slow down Mail. To keep it running quickly, you can run the following command from the terminal:
Code: Select all
/usr/bin/sqlite3 ~/Library/Mail/Envelope\ Index vacuum


I set this up as a Hazel rule as follows:
On folder Applications, if name is Mail and date last matched is not in the last 1 week,
Run embedded script:
/usr/bin/sqlite3 ~/Library/Mail/Envelope\ Index vacuum

You can leave the default shell set as /bin/sh

Note that this will work on any program that has an Envelope Index, such as Yojimbo. To find out which programs you use have this file, open a terminal and type the following commands:
Code: Select all
cd ~
find . -name 'Envelope Index' -print


You will then get a list of all the files you can run this on.
jayhawkbabe
 
Posts: 17
Joined: Sun Jun 15, 2008 10:39 am

Thanks for the scripts (here and in your other threads).

I wanted to point out that the embedded script option is in the 2.2 beta so those of you using the 2.1.x series will need to save the script to a separate file and have Hazel run it.

The script in this case would need to look like:

Code: Select all
#!/bin/sh
/usr/bin/sqlite3 ~/Library/Mail/Envelope\ Index vacuum
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Oops, I didn't realize that because I hadn't used embedded scripts until after upgrading to the current beta. Thanks, Mr. Noodle.

If you're using an external file, be sure to make it executable. To do this, open up Terminal and "cd" into the directory containing your script. (Alternatively, you can navigate to the directory in Finder and then drag the icon from the top of Finder into the Terminal.) Then type the following command in Terminal:
Code: Select all
chmod 755 name_of_your_script
jayhawkbabe
 
Posts: 17
Joined: Sun Jun 15, 2008 10:39 am

Re: Speed up Mail--Keep Envelope Index clean Wed Jun 25, 2008 12:49 pm • by sjk
jayhawkbabe wrote:On folder Applications, if name is Mail and date last matched is not in the last 1 week

Can you explain why you've picked the /Applications folder and that rule condition to trigger the script? Wouldn't it be clearer and more efficient to watch the ~/Library/Mail folder with a condition on the Envelope Index file, like:

Code: Select all
[Folder]
~/Library/Mail

[Rule]
If all
Name is Envelope Index
Date Last Modified is not in the last 1 Week

and maybe add "Subfolder Depth 0" (or 1?) to the rule (with Hazel 2.2)? Seems like overkill for Hazel to watch the /Applications folder unless it's got multiple rules configured for it.

Thanks for helping me better understand the logic for this kind of matching.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

I already had rules in the Applications folder--that's why I picked it. You can essentially pick any folder/file that will always be there.

I have wondered if it is necessary to quit mail (the script doesnt do this, but could quite easily) and then reopen it after the script has run. I've never had issues with it running while Mail is open to date, however.
jayhawkbabe
 
Posts: 17
Joined: Sun Jun 15, 2008 10:39 am

Re: Speed up Mail--Keep Envelope Index clean Wed Jun 25, 2008 5:28 pm • by sjk
Your "Date Last Matched is not in the last 1 Week" condition is clever; I might find a use for something like that.

There was plenty of discussion about Envelope Index vacuuming when the suggestion was popularized awhile back. Pretty sure quitting Mail before doing it was recommended but I don't recall any specific details. I only did it once since the results were insignificant and it wasn't worth risking unforeseeable side effects.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Glad you liked the rule for weekly vacuums. Now if I could only make one for my vacuuming my house..hehe.

I wondered the same thing about quitting mail first. I considered building in a quit/restart command, but then decided that would be annoying if I were in the middle of reading/writing email. (One could have applescript check to see if Mail is the active application though and only run the rule if it isn't....) Regardless, I have been running this rule without quitting mail for several months now with no problem...so I guess I'm not going to worry all that much about it.
jayhawkbabe
 
Posts: 17
Joined: Sun Jun 15, 2008 10:39 am


Return to Tips & Tricks - DO NOT POST QUESTIONS