Problem Filing a Message In Apple Mail

I have been building a macro to dynamically generate a menu and based on user selecting a number (originally 1-9) it would file an email in a specific folder. I started to expand the macro with additional cases, but now with the number 10, it never seems to match that case even when I can see the variable is set to 10 before entering the switch. In reviewing with matcher, I noticed that there seems to now be a "is=" condition which I can't find documentation on. Previously I had used "contains" which breaks since "1" will match "10", but switching to "is" never matched and "is=" somehow never even hits the "otherwise" condition, so I can't tell what is happening.

Any help would be greatly appreciated

Show brings rapid help, while tell is always left waiting.

Can we see the macro (or at the very least, the relevant part of it ?)


Hey David,

Post the macro itself as well.

No one has time to reinvent the wheel, and the easier you make it for them to test the more likely you'll get useful help.

How to Post Your Macro to the Forum

If you haven't read this it's worth a couple of minutes of your time.

Tip: How Do I Get The Best Answer in the Shortest Time?


Hey David,

I get the feeling you're going about this in a way that is overly opaque to the user.

If you use a Prompt With List action with mailbox names instead of numbers I think your workflow will be smoother.



File Emails via User Prompt with List v1.00.kmmacros (6.5 KB)

Thanks for both responses, I was starting to look at how to sanitize the macro and in the process that what I thought was the problem may actually be wrong. The mail folders are nested and in general I don't keep everything expanded. Mail has a nuance where the menu for moving messages dynamically varies by what is visible based on the currently expanded folders. Anything which is still nested requires navigating through the sub-menus.

What I seem to be finding is that the items which have a problem are the ones which are nested a few layers deep. Although the select menu items let's me navigate down to the specific folder, it seems that they don't reliably work. I think the initial switch case issue was mostly a red herring based on an initial bug in my code, and now I'm working on a different problem.

I'm not sure if I need to insert a delay of some sort (if that's possible) to let the UI keep up with the navigation through the menus. Here is the Macro in case I'm wrong and instead missing some other obvious problem.

I think the real problem is coming from the number of submenu nesting.

Hey David,

Personally I use Mail Act-On and MailHub for this kind of task and find them indispensable.

Unfortunately Mail Act-On is now only available as part of SmallCubed's MailSuite, and that's quite expensive.

I only see working versions of Mail Act-On up to Mojave, and that worries me. I'll have to talk to the dev and find out what's going on.

In any case – I used AppleScript for filing messages long before the plug-ins were available.

⇢ How many messages are you processing at once?

Where are you filing to?

On My Mac mailboxes?

Or IMAP account mailboxes?

This can be done with AppleScript, so you can avoid messing with the menu structure of Message › Move to.

Once I have more information I can probably whip up the move-to code.

Also – what version of macOS are you using?

Note that Keyboard Maestro has a number of Apple Mail related text tokens.

Look at KM Menu Bar: Edit › Insert Token › Mail...


Thanks for the pointers. This is daily processing 200-300 emails a day. They are being filed within IMAP on Big Sur. I'm going follow on your Apple script idea. It looks like in AppleScript the mailbox name doesn't require any understanding of the folder structure. so I can just call the name directly. Does this look like what you were thinking for the move piece?

tell application "Mail"
   set tgtMailbox to (first mailbox whose name is "Project 1") of account "Work"
   set selMessages to selected messages of message viewer 1
   repeat with selMessage in selMessages
      set mailbox of selMessage to tgtMailbox
   end repeat
end tell

Hey David,

I spent some time testing on both my Sierra and Mojave machines, and I'm sad to find out that Mail is still egregiously slow when filing multiple messages with AppleScript.

I think filing 30 messages took around 10+ seconds on both of my systems.

Preposterous! Mail Act-On and MailHub can do it in a flash.

When doing this many times per day the sluggishness may become oppressive.

If the AppleScript works satisfactorily for you then great – if not then there's an alternative.

Note the mailboxes in highlighted in the toolbar:

You can drag and drop mailboxes in that space and move them around with Cmd-drag.

They show up in the Mailbox › Move to Favorite Mailbox menu with assigned keyboard shortcuts:


You can use these keyboard shortcuts directly, or you can reassign them using the system keyboard preferences or Keyboard Maestro.

You can also assign keyboard shortcuts to mailboxes in the menu structure by name, as long as the name is unique. Even if the mailbox moves around in the menu due to the arrangement of the side-bar, the keyboard shortcut will stick with it.

Screen Shot 2021-01-28 at 21.37.19

The only problem with this approach is that if messages are marked Unread they will be marked Read when you move them.

If that's not a problem for you then this approach will save you many seconds per day.


Thanks for all the time you have spent looking at this. I think I've been lucky so far that in general I'm not batch processing emails, but reading and filing so I may not notice the delay as much since I'm reading the next email. I didn't know the trick with the favorite email folders, which is really nice. I'll need to spend some time looking at the two apps you recommended as longer term solutions.

Thanks again for all your time spent looking at this.


1 Like