Fix Search Issues and Speed Up Apple Mail with This Simple Script

In Apple, Fix It, General, HTD Tech Tip, Software by Michael Sheehan3 Comments

Today I was trying to find an email in my Apple Mail and went to my usual trustworthy internal mail search function only to find that the “Entire Message” field was grayed out for all of my accounts. Granted, I use a mixture of POP3 and IMAP account and my main IMAP account has about 8400 messages in my inbox (hmm, maybe I should start filing those?).

After doing some quick searches, I came across a little script or command that you can run in the Terminal which helps to optimize your email subject lines. In fact, after reading through some of the comments on this post which talks about the process, you can run the same command of “vacuum” on a variety of the tables within your database (e.g., addresses, messages, attachments, threads, etc.).

The Script

Here is the simple script that you can run:

  1. Exit out of your Mail application
  2. Launch Terminal (if you don’t know what this is, you might want to just get the Automator script that is linked below).
  3. Type in the following:
    cd ~/Library/Mail
    sqlite3 Envelope Index
  4. You will see a new prompt that says “sqlite>”
  5. At the prompt, type (don’t forget the semi-colon):
    vacuum subjects;
  6. It may take a few seconds (it took mine a while) for the script to run. This depends on the size of your mail database
  7. When the script has finished, you will see the “sqlite>” prompt again.
  8. Push CTRL-D to exit out of sqllite.

That’s all that you have to do. You will definitely see some improvements in your Mail application speed. Also, this corrected the error that I found with the “Entire Message” field being dimmed out. Corrected resulting image shown below:

Additional Cleaning

I read through some more of the comments and one user commented that you can also “vacuum” other tables. I have not tried that so let me know what the results are if you try it. To do that, after the “vacuum subjects;” command, simply type:

vacuum addresses;
vacuum messages;
vacuum attachments;
vacuum threads;

There are some other tables in there (like “properties”) but I think the ones above are the most critical.

Automate It


Lastly, you can download an Automator script that can do this for you automatically. And, you might even want to tie it to a Calendar event to run every month or so. The Automator script can be downloaded here. From what I can tell, it simply runs the “vaccum;” command on everything. To set up the Automator script based on a calendar event, do the following:

  1. Download Mail Vacuum 1.1
  2. Unzip and move the Automator script somewhere where you can save it (e.g., the “Applications” directory)
  3. Open the script in Automator
  4. Choose “Save as” and then select type “Application”
  5. Exit Automator
  6. Launch iCal
  7. Create a new Event
  8. Under the Alarm section, choose “Open File”
  9. Choose the Automator Application you just created.
  10. Set up a repeating event (optional) – I set mine to repeat monthly for a year.

From my understanding, the SQLite “vacuum” cleans up the main database “by copying its contents to a temporary database file and reloading the original database file from the copy.” This does some essential database optimizations. More details on the SQLite “vacuum” command can be seen here.

Did you find this solution useful? If so: [paypal-donation reference=” vaccum”]

HTD says: Let me know how this tip works for you! It definitely fixed my search problems!