If you’re using Apple’s Mail application on the Mac you’ve probably seen the app slow down over time. One reason why this can happen is because the database used by Mail to store messages can grow to a large size thanks to message fragmenting and gaps in the database when messages are deleted.
Lucky for you there’s a fairly simple solution, made even simpler by using Automator, Apple’s easy-to-use app for automating tasks that often need to be performed repeatedly.
And isn’t that at least part of the reason why people invented computers to begin with–to handle the mundane tasks that repeatedly pop up in our lives?
The road map
Our goal is this: Make Mail faster by cleaning up the mail database.
Because it’s not a good idea to try to do maintenance on an open Mail database, it’s best to quit Mail first, clean things up, then re-open Mail and see if the clean-up resulted in a speed-up.
So, our steps are:
Quit Mail.
Clean up the mail database.
Open Mail.
Automator makes this really easy.
How Automator works
Automator executes a series of actions to achieve a result. You don’t need to know any fancy scripting or programming languages to use Automator. In this example, though, we will use one UNIX command. But we’ll make it easy by simply copying and pasting it when the time comes.
Now, let’s dive in.
Making the workflow
Open Automator (From the Finder’s Go menu, choose Applications and scroll in the window that appears to find Automator.)
In the window that appears, click New Document.
In the sheet that appears, select Workflow and click Choose. Our first step is to quit Mail if it’s running.
In the search field above the list of actions, type quit.
Drag the Quit Application action into the Workflow area.
From the Quit Application pop-up menu, choose Mail. Leave the Ask to save changes box checked. When you’ve finished steps 4, 5, and 6, your workflow window should look like this.Our second step is to issue a command using the shell, an interface to the UNIX system that is running on your Mac.
In the search field above the list of actions, type shell.
Drag the Run Shell Script action into the Workflow area underneath the Quit Application action.
Select all the text in script shell script box and copy and paste the command below depending on which version of the OS is running on your Mac. Be sure to include the semi-colon at the end of the line.
For Snow Leopard (10.6): sqlite3 ~/Library/Mail/Envelope Index vacuum;
For Lion (10.7), Mountain Lion (10.8), Mavericks (10.9), or Yosemite (10.10): sqlite3 ~/Library/Mail/V2/MailData/Envelope\ Index vacuum;
For El Capitan (10.11): sqlite3 ~/Library/Mail/V3/MailData/Envelope\ Index vacuum;
For Sierra (10.12): sqlite3 ~/Library/Mail/V4/MailData/Envelope\ Index vacuum; When you’ve finished Step 9, your workflow should look like this. In our example, we’ve copied and pasted the command for macOS Sierra (version 10.12). The vacuum command cleans the mail database by copying its contents to a temporary file and rebuilds the database into a smaller amount of disk space. This eliminates gaps, defragments the data, and cleans up the database file structure. Our last step is to re-open Mail so we can see if the app feels faster and more responsive. 10. In the search field above the list of actions, type open. 11. Drag the Launch Application action into the Workflow area underneath the Run Shell Script action. 12. From the Launch Application pop-up menu, choose Mail.Congratulations! You’ve made a workflow. And those are our three steps. Now save the workflow. 13. From the File menu, choose Save… and name your new workflow. To run the workflow, click the Run button in the upper right-hand corner of the workflow window. Mail will quit (if it’s running), the database will be cleaned up, and a speedier Mail will be reopened.
But that’s not all
You can run this Automator workflow anytime you want by double-clicking it to launch Automator and clicking the Run button.
But as we said earlier at least part of the reason why people invented computers to begin with was to handle repetitive tasks.
Wouldn’t it be great if the Mac would simply clean up the Mail database every month without we humans having to worry about it?
Well, guess what….
Automating the Mail database clean-up
Let’s have the Mac do all the lifting, both heavy (cleaning up the database) and light (doing it for us).
One of the types of Automator documents that you can choose from is a Calendar Alarm. We could have created this workflow as a Calendar Alarm at the start, but we can also convert the workflow to a Calendar Alarm now.
From the File menu, choose Convert to….
A copy of the workflow will be made in a new Automator window. Select Calendar Alarm and click Choose.
From the File menu, choose Save….
In the sheet that appears, give your calendar event a name and click Save.
Mail will create a new calendar named Automator within the Calendar app on your Mac. The Calendar Alarm will be created as an event on the date and time it is saved, and the workflow will run.
You can open the event and rename it, move it to any other calendar, change the time, and set it up as a repeating event (say the first day of every month), just like any other calendar event.
Go forth and vacuum!
Now that you’ve seen how easy it is to keep Mail running smoothly, fire up Automator and make your experience with Mail just a little bit better. Did this help your Mail workflow? Let me know in the comments section below!
Related
Mike Matthews
Mike Matthews has used Apple products since the days of the Apple II+ and Applesoft Basic. He appreciates the fact that people no longer have to start up apps by loading them from a cassette tape recorder.