Mac Automator App Schedule Script

Reader Collin Merrill would like to automate a common, but potentially risky, task on his Mac. He writes: I was just wondering if you had an Automator workflow to automatically empty the trash. Dec 07, 2013  There are several ways to do this, but if you want to schedule the app to quit automatically with iCal here's one thing you can do: Open Script Editor (in /Applications/Apple Script/) Create a new script with this line: tell application 'IMSafe' to quit; Save the script somewhere and name it something like 'Quit IMSafe'. Jun 13, 2016  To control the user interface of an app, you must first inspect the app and determine its element hierarchy. This can be done by querying the app. For example, Listing 37-2 asks Safari for a list of menus in the menu bar. Open in Script Editor. Listing 37-2AppleScript: Querying an app for user interface element information.

If you use Apple's Mail app on your Mac, you've probably had times when the application slows down. Messages in mailboxes are slow to appear; searches take longer than usual to perform. This can happen when Mail's mailboxes (or folders, if you prefer) accumulate thousands of messages — which is all the more likely if you're among the majority of the human population and you don't discard old email.

The best thing you can do is be ruthless with old email. Once you're finished with a message, move it to the trash and then empty the trash every so often. Try to think about it this way. We all receive tons of junk mail in our physical mailboxes — advertising circulars from the local supermarket, catalogs, credit card applications. If you don't save any of that stuff, why would you hold on to old email, particularly when it takes less effort to press the delete key than it does to carry paper-based mail to the recycle bin?

Still, some of us accumulate email that is valuable and merits keeping. That's fine, too, but over time it still may slow the Mail app down.

Lucky for all of us, there's a solution to the slowdown.

Scripting to the Rescue

There's a built-in tool on your Mac called vacuum that you can use to clean up the database that stores all of your emails. The vacuum command copies the contents of your mail database to a temporary file and rebuilds it so that it uses less space on your disk. The vacuum command eliminates gaps, defragments the data, and cleans up the database file structure.

Normally, the vacuum command is accessible only through the Mac's command-line interface using an app such as Terminal. But thanks to the wonder of Automator, an app that ships with your Mac, you can create a simple three-step script that will run the vacuum tool. And you don't have to know how to write a script, use the command line, or even understand how the vacuum tool works.

Here's how to do it.

First Things First

Mac automator download

Apple has been improving the security of macOS every year. One of Apple's more recent security features is called Full Disk Access, introduced with macOS 10.14 Mojave. Normally applications do not have the ability to access all the files on your Mac, including data from other apps. Enabling Full Disk access for an application grants that app the ability to fiddle with data from other apps.

To make this Automator script work properly with macOS Mojave or macOS Catalina, you'll need to enable Full Disk Access for Automator. Here's how:

  1. From the Apple menu, choose System Preferences.

    Source: Mike Matthews/iMore

  2. Click Security & Privacy.

    Source: Mike Matthews/iMore

  3. Click Privacy.

    Source: Mike Matthews/iMore

  4. If the preference pane is locked, click the lock to make changes. When prompted, enter the user name and password you use to log in to your Mac.

    Source: Mike Matthews/iMore

  5. Click Full DIsk Access.

    Source: Mike Matthews/iMore

  6. In the list that appears on the right side of the Privacy window, check the box for Automator.

    Source: Mike Matthews/iMore

  7. Click the lock to prevent further changes.

    Source: Mike Matthews/iMore

Meet Otto

Open the Automator app which is located in your Mac's Applications folder. Its icon looks like a robot refugee from Earth, circa 2805.

  1. In the Finder, choose Go.
  2. Click on Applications.

    Source: iMore

  3. In the Applications window that appears, locate the Automator app and double-click it to open it.
  4. In the window that appears, click New Document.

    Source: iMore

  5. In the sheet that appears, click Workflow.
  6. Click Choose.

    An empty Automator document will open. To build our Automator script, we will drag actions from the left side of the window to the right side. As a first step, we want to quit the Mail app if it is open to make sure Mail's database does not change while we are cleaning it up.

    Source: iMore

  7. In the search field type the word quit.
  8. Drag and drop the action named Quit Application to the right side of the window.

    Source: iMore

  9. From the pop-up menu in the Quit Application action, choose Mail.
  10. Clear the search field above the list of actions and type the word run.

    Source: iMore

  11. Drag and drop the action named Run Shell Script beneath the Quit Application action.
  12. In the empty field in the middle of the Run Shell Script action, copy and paste the command below that corresponds to the version of macOS that is running on your Mac. Don't forget 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;
    • For High Sierra (10.13): sqlite3 ~/Library/Mail/V5/MailData/Envelope Index vacuum;
    • For Mojave (10.14): sqlite3 ~/Library/Mail/V6/MailData/Envelope Index vacuum;
    • For Catalina (10.15): sqlite3 ~/Library/Mail/V7/MailData/Envelope Index vacuum;

    Source: iMore

  13. Clear the search field above the list of actions and type the word launch.

  14. Drag and drop the action named Launch Application to the right side of the window beneath the Run Shell Script action.

    Source: iMore

  15. From the pop-up menu in the Launch Application action, choose Mail. The script is now complete, but you'll need to save it.

  16. Click on File in the Menu bar.
  17. Choose Save.

    Source: iMore

  18. In the sheet that appears, give your workflow a name, and pick a place to save your new Automator script.

To run your new workflow, just open it with Automator and click the Run button in the upper right corner of the script's window. If Mail is running, it will quit, the script will run, and Mail will re-open with a rebuilt database behind the scenes which should lead to improved performance.

Hoover it Up!

Has this easy-to-make Automator action helped with your Mail slowdowns? Let us know in the comments below.

macOS Catalina

Main

We may earn a commission for purchases using our links. Learn more.

Home > Articles > Apple > Operating Systems

  1. What Is AppleScript?
Page 1 of 4Next >
If you're an avid Mac user, you've probably heard of two technologies that seem sort of alike: Automator and AppleScript. Ben Waldie points out the differences and similarities in the two technologies, explaining when to use each one to save yourself some keystrokes (and headaches).
From the author of
Automator for Mac OS X 10.5 Leopard: Visual QuickStart Guide
Automator for Mac OS X 10.5 Leopard: Visual QuickStart Guide

For many Mac users, AppleScript and Automator are terms that bring about a sense of confusion. This is unfortunate, considering that both technologies are generally targeted at typical users (non-programmers, in other words) and designed to make life easier through automation.

Much of the confusion centers on the similarities between these two applications:

Mac automator app schedule script free
  • Both automate time-consuming or repetitive tasks.
  • Both interact with Mac applications.
  • Both are targeted toward everyday Mac users.

But AppleScript and Automator are actually quite different. This article will attempt to clear up some of the confusion surrounding these technologies.

What Is AppleScript?

AppleScript is a scripting language that has been built into the Mac operating system since the early days of System 7. Like the rest of the operating system, AppleScript has steadily improved and expanded over the years.

With AppleScript, you write a script—essentially a set of instructions—to perform tasks within the existing applications on your Mac (the application must support AppleScript), or within the operating system itself. Scripts are typically written in an AppleScript editor such as Script Editor, which you can find in the following folder on your Mac:

After writing your script, you can run it from within Script Editor, or save it and run it as an application.

Aside from some basic user-interaction capabilities, AppleScripts don't normally have interfaces. Once launched, they simply appear in your Mac's dock, and they run virtually invisibly.

Unlike programming languages such as Objective-C and Java, AppleScript's syntax is much like the English language, which means that users can learn it quite easily with no prior scripting or programming experience. Mac users often create simple scripts by trial-and-error, or by copying and pasting together pieces of existing scripts found online.

Automator Schedule Script

Apple provides some sample scripts with AppleScript; look in the following folder on your Mac:

Even without any prior knowledge of AppleScript, if you open some of these scripts in Script Editor you'll probably be able to figure out what many of them do (see Figure 1).

Figure 1 The New Applications Window sample script.

Related Resources

  • Book $55.99
  • eBook (Watermarked) $55.99

Mac Automator Tutorial

  • Web Edition $55.99