Using AppleScript to Open a Specific Mailbox in Apple Mail (MacSparky Labs)

Shortcuts for iOS 16 is adding a feature that lets you open a specific Mailbox in Apple Mail on your iPhone or iPad. Shortcuts for Ventura, however, doesn’t have that function. What gives? Never fear. Sparky figured out a way to duplicate the feature using AppleScript…

This is a post for MacSparky Labs Level 3 (Early Access) and Level 2 (Backstage) Members only. Care to join? Or perhaps do you need to sign in?

Will MailKit Save Mail.app?

One of the announcements to come out of WWDC this year is a new framework for third parties to create plugins for Apple’s Mail.app called MailKit. Mail.app has been stagnant for a long time. While the app continues to get support for email rendering and improvements to its basic functions (like search), that’s about it.

Most who use it day-to-day have gotten somewhat accustomed to how dated it feels. Making a stable, feature-rich email application isn’t easy. Most third-party developers seem to fall down on the “stability” part. Apple nails that but seems uninterested in the “feature-rich” part.

I hope that this new MailKit will allow third-party developers to pick up that slack. There is already a rich ecosystem of Apple Mail plugins, but I’ve become increasingly leary about using and recommending them during recent years. My concern was that Apple could, at any point, pull the plug on Apple Mail plugins.
A few years ago, I talked to an Apple engineer at WWDC who explained that mail plugins, historically at least, represented a security vulnerability, and Apple is very much interested in removing any security holes. The good news is that the announcement of MailKit means Apple is not pulling the plug on plugins but instead found a safe way for them to continue while keeping the platform secure.

This new sense that mail plugins have a future path and will continue to exist makes it easier for me to use them. I hope this also encourages other developers to get off the sidelines and explore developing new and helpful Mail.app plugins. Hopefully, another benefit will be that in future updates to macOS, plugin developers won’t have to re-invent the wheel every year. One of my favorite plugins is SmallCubed’s MailSuite, but every year I have to turn it off on beta machines and often for the first few months after a macOS update releases.

Unfortunately, MailKit is only for the Mac, leaving Apple’s Mail app on the iPhone and iPad sad and lonely, still without even the dignity of a sharing button. I’d love to see MailKit also make its way to iOS and iPad OS, but I’m not holding my breath.

Updates and Improvements to the Salutation AppleScript for Apple Mail

My relationship with Apple Mail isn’t love so much as familiarity. However, every time I think about walking out on Apple Mail, I think about our long and complicated relationship, and how much work I’ve put into it with things like my salutation AppleScript.

The Updated Script

Using a combination of AppleScript and TextExpander, I’m able to automatically insert an email salutation by typing “xhi”. This is really useful and something I run multiple times a day. The original post and explanation on how it works is still good. However, the script has altered a bit. You can download the updated version, called “xnm” (“X Name” in my head) here. I suggest running it as an embedded TextExpander snippet so you can combine it with a variety salutations like “Hi”, “Hello”, “Dear”, “Hey”, and whatever else floats your boat. Also, you can download the TextExpander group with both the “xnm” and “xhi” snippets here. That should be all you need to get this rolling.

But What About Multiple Recipients?

Reader Mark Bramhill had that exact question and came up with two variations of this script. The first will make a salutation for everyone in the “To:” field. If you regularly (or occasionally) send email to multiple recipients, this variant is for you.

Download Multiple Recipients AppleScript

That, however, wasn’t enough for Mark. He made a separate AppleScript that counts the number of recipients. If there is just one recipient, it inserts that person’s name. If there is more than one (including looking at the cc: field), the script instead writes “Y’all”. I thought both of these scripts were pretty clever.

Download the “Y’all” Script

Language Specificity

I also had several emails from non-english speakers about the script not working. The trouble is in this line:

tell text field "To:" of window 1

As you can see, the script is language-specific. In English, the script looks for the “To:” field, but in other languages, that field has a different name. In Dutch, for instance, it’s “Aan:”. If your native language isn’t English, you’ll need to fix that line appropriately.

I do love how this script has taken on a life of its own. This isn’t a testament to anything particularly bright on my part but the utility of a script that auto-salutes every email you send. This feature is so useful that I’m shocked it isn’t baked in to all email applications.

Giving Up on Apple Mail Flags

As I have lamented too many times on Mac Power Users, I seem to be able to find email apps that I can live with, but not fall in love with. So many third-party apps are unreliable, and Apple Mail just refuses to evolve. Nevertheless, for some time now, I have been managing email with Apple Mail, but only after I add features to it with SaneBox (a sometimes sponsor of this blog) and, on the Mac, SmallCubed’s MailSuite.

Even after bolting on these tools, I still find myself primarily managing email on my Mac and treating the iPhone and the iPad as email triage machines on the rare occasion that I even look at email on those devices. For about a year now, I have been using colored flags for email in that triage role. Whether an email is customer support or a general feedback issue, it gets a specific colored flag. The same goes for legal and personal email. The problem I keep running into, however, is that Apple Mail cannot keep track of the flags. Sometimes a flag applied on the iPhone shows up on the Mac; sometimes it does not. Moreover, once I clear the flags that do make it over to the Mac, those flags may get cleared over on the iPhone. Then again, they may not. I would go through a whole process of checking the flags I cleared on the Mac to see if they made it over to the iPhone and iPad, and vice versa. I finally realized the madness of it all a few weeks ago when my flag counts were Mac (17), iPhone (34), and iPad (12). Enough!

So I have created IMAP folders with categories such as “Customer Support” and “Process” that hold email between my devices. The folders never get out of sync, and while it is slightly more work to move the messages into folders compared to flagging them, it is worth it to have a system I can rely on. A few additional points on this workflow:

  • This is not a beta problem. While I am running some devices on the new betas, flags have not been syncing for me for a year now.

  • I struggled with the name of the folder to hold email for later processing. The Hey.com service uses the term “Focus & Reply”, which sums it up nicely, but I prefer one word. I ended up with “Process”, because that is what I try to do with that folder every day.

MailSuite Beta


Screen Shot 2018-10-15 at 4.51.39 PM.png

One big change with Mojave was Apple’s tightening up of the mail plugin mechanism. As a result mail plug-in makers have been hard at work bringing their products in line with the new security protocols. Today SmallCubed, makers of MailTags and Mail Act-On released the beta of its new product, MailSuite, a combination of all of its Apple Mail plugins in one, new product. It is still in beta but I’ve been running it this afternoon with no problems. I’ll be happy when it gets released.


While I’ve toyed with the idea of tagging email, it kind of falls apart when you get to iOS and don’t see your tags. Mail Act-On however, is an absolute beast when used in conjunction with SaneBox to move mail messages (or groups of mail messages) into mailboxes – including deferred email folders – via keyboard shortcut. Mail Act-On also has the ability to delay-send emails, which just might save your bacon one day.