Auto Filer: Using Shortcuts and MsgFiler to Automatically File and Suggest Mailboxes

One of the most requested features that I’ve received from users over the years is for MsgFiler to auto-suggest mailboxes based on the selected email message in Mail. For the longest time, I’ve been resistant to add this primarily because my knowledge of AI and ML technologies was scant. It still is, but there have been enough advances in the field that I will look into this in the future. In the meantime, however, I have created a workflow using Apple Shortcuts and MsgFiler by which users can create custom rules to instruct MsgFiler to automatically files messages into mailboxes.

Now, before you go off and say, “Why can’t you just create a rule in Mail to process incoming messages?” You certainly can, but the use case for most MsgFiler users is to file messages after they have appeared in the inbox, which happens after mail rules have run. I personally don’t have many mail rules, because I prefer to triage my email from the inbox.

In this article, we’ll dive into the Auto Filer shortcut, guiding you through the process of creating rules — based on the sender, subject, message body, or raw source — applied to the selected message or messages in Mail. Any message that meets one of these criteria will be automatically filed into the specified mailbox.

MsgFiler 4 has extensive support for Apple Shortcuts. Apple describes a shortcut as “a quick way to get one or more tasks done with your apps. The Shortcuts app lets you create your own shortcuts with multiple steps.”

MsgFiler exposes the following actions in Shortcuts. A fuller description of these actions can be on the MsgFiler Documentation website.

  • File Messages
  • Find Account
  • Find Mailbox
  • Get MsgFiler Setting
  • Get Selected Email
  • New Mailbox
  • Set Filing Focus
  • Set MsgFiler Setting
  • Set Search Query
  • Show Mailbox

In the Auto Filer shortcut, we’re using the Get Selected Email, Find Mailbox, and File Messages actions.

Downloading the Auto Filer Shortcut

Follow these directions to download and install the Auto File shortcut:

  1. Click the button below.

  1. A browser window may open. Click Get Shortcut, followed by Allow.
  1. Next, the Shortcuts app will open when you click on the link, asking you for permission to install the shortcut into your library. Click Add Shortcut.
  1. Find the Auto Filer shortcut in your Library and double-click on it. You should see the following window:

Configuring Auto Filer

When you install the shortcut, you’ll be taken to a setup screen where you can configure the three of the following four options.

  1. Search Rules
  2. Selected Messages
  3. Confirm Search Query
  4. Show Notification

Search Rules

Configure the Text action with all the rules for each search type, along with the mailbox to file messages. A rule consists of three items, with each part in the rule separated by a delimiter (default is ##).

  • Search Type: Enter either Sender, Subject, Body, or Raw Source. What you enter here will determine what type of query to perform on the selected messages.
  • Search Term: Enter the string you want to search for in the search type.
  • Mailbox: Enter the mailbox path query. If a rule matches, this is what will be sent to MsgFiler.

Example Rules

Here is an example of a set of sample rules:

Sender##Gumroad##Finances/Gumroad Sales
Subject#[MsgFiler]##Work/MsgFiler
Raw Source##MsgFiler##Work/MsgFiler

And a description of each rule as follows:

Search TypeSearch TermMailbox
SenderGumroadFinances/Gumroad Sales
Subject[MsgFiler]Work/MsgFiler
Raw SourceMsgFilerWork/MsgFiler

Add your own entries on a new line.

Selected Messages

By default, the Get Selected Messages action does not retrieve the body or raw source from selected messages. For the body, this is because AppleScript can sometimes take a long time to retrieve message body contents, especially if it has an HTML component (which many emails do). I have found requesting the raw source to be faster, but note that if you have many messages selected, performance may be slower when either body or raw source is checked.

Note: This is the option that you’ll have to configure post-setup (for some reason, Shortcuts did not allow me to offer the option to check/uncheck Include Raw Source).

Confirm Search Query

If you want the Auto Filer action to show you the matched mailbox query after processing all the rules, set this value to 1. Otherwise, set to 0.

Show Notification

If you want a notification to appear when Auto Filer finds a single mailbox match and automatically files to that mailbox, enter 1 for the variable Show Notification for Automatic File.


Running the Shortcut

Once you have configured the shortcut with all of your rules, it’s time to run it and see what happens.

  1. First, select a message in Mail. If no messages are selected in Mail, the Shortcut will display an alert to you.
  2. Click the Run button in the top of the shortcut.
  1. If MsgFiler finds a match, it will display the matched mailbox query term it will pass to MsgFiler if you set 1 for the variable Display Query Before Filing.
  1. Click OK.
  2. MsgFiler will now send the mailbox query term to find matching mailboxes.
  3. If there is only one mailbox match, MsgFiler will file the selected messages to that mailbox.
  4. If there are multiple mailbox matches, MsgFiler will display a popup with all the mailboxes matching that criteria. Choose the mailbox you wish to file the selected messages to and click OK. Here is an example of using the mailbox query term “Test”.
  1. If there are no mailbox matches, MsgFiler will open, allowing you to type in the mailbox name yourself. In the screenshot below, the mailbox search query “Testddfd” didn’t match any mailboxes, so MsgFiler 4 will open with that query in the search field.

Applies to All Messages in Selection

It is important to note that this shortcut applies its filing operation on all messages in the selection and does not process each message individually. Keep this in mind if you try to file multiple messages at a time or if the selected message is actually a threaded conversation.

Accessing the Shortcut Globally

There are many ways to run this shortcut globally. One way, however, seems to result in an error in Mail, so do not do the following:

Don’t do this

Mail lets you assign a global keyboard shortcut in the Details section of your shortcut. But, I have found this displays a strange error in Mail when invoked.

The action still completes, but the error will disrupt your filing flow, so I do not recommend using this method.

Global Shortcut Workaround Using Automator

Here is a workaround if you want a global keyboard shortcut. First we will add an application to your Dock that calls the Auto Filer shortcut.

Add to Dock

  1. Open Shortcuts.
  2. Edit your shortcut.
  3. Choose Add to Dock from the File menu.

A file pointing to your shortcut is created in your user Applications folder, ~/Applications, not to be confused with the computers /Applications folder. This app will also be placed at the end of the Dock.

You can now remove the icon from the Dock, and the app will still reside in your user Applications folder.

Keyboard Shortcut via Automator Quick Action

Next, we’ll create a Quick Action in Automator that we’ll bind a keyboard shortcut to.

  1. Open Automator.
  2. In the window that appears, double-click Quick Action.
  3. In the window that appears, enter “Launch Application” in the search field.
  4. Double-click Launch Application.
  5. Choose Other from the application drop-down menu.
  6. Navigate to the Auto MsgFiler shortcut in ~/Applications.
  7. Save the workflow as Open Auto Filer.
  1. Open System Settings.
  2. Choose Keyboard from the list on the left.
  3. Click Keyboard Shortcuts….
  1. In the sheet that appears, click Services.
  2. Click the disclosure triangle next to General.
  3. Enter a keyboard shortcut for Open Auto Filer. For instance Control-Option-Shift-Command-M.
  4. Click Done.
  5. Close System Settings.

To test this, do the following:

  1. Open Mail.
  2. Select a message.
  3. Press Control-Option-Shift-Command-M.

The Auto Filer shortcut will now run. If a rule matched to a single mailbox, you will see the selected message automatically get filed.

Stream Deck

If you have an Elgato Stream Deck, you can assign an Open button to launch the Auto Filer shortcut in your ~/Applications folder.

Then, when you’re filing email, you can press the button and have your messages automatically filed when a rule is matched! Save even more time using the Auto Filer shortcut!

Wrapping Things Up

By customizing the Auto Filer shortcut, you can have rules that automatically file messages directly into mailboxes without you having to type them in MsgFiler. You can imagine in the future, passing in the sender, subject, raw source, or message body into an local, on-device, AI that knows about your filing history and can more intelligently parse, analyze, and choose the right mailbox to file to or suggest in MsgFiler.

Leave a comment down below if you incorporate Auto Filer in your filing workflow. If you extend the shortcut to do additional things, I’d also like to know in the comments section. Happy filing!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.