Generating Markdown links to email messages with shortcuts and AppleScript

0

One of the system app updates we covered on AppStories this week that excites me the most is Mail. The app will finally introduce several advanced features this fall, including:

  • Undo send, allowing you to recall a message for 10 seconds after a message has been sent
  • Message scheduling with suggested, fully customizable future delivery times and dates
  • Tracking, which exposes requests you’ve made in messages that you haven’t received a response to
  • Remind Me, a snooze-like feature to schedule messages to reappear later in your inbox
  • Missing recipient and attachment alerts
  • Improved search

For the first time in a long time, this list makes Mail a much more attractive alternative to third-party apps. Mail won’t match all the features offered by third parties, but my needs for advanced email client functionality are quite modest, which I think puts me squarely in Apple’s target demographic.

Until recently, my email usage was split between Mimestreamavailable only on Mac, and Spark on iOS and iPadOS. The separation wasn’t ideal, but since I manage most of my email on my Mac, I tolerated it.

For the past few weeks, I’ve used Mail exclusively on all my devices, which has been a refreshing change of pace. Still, it’s not perfect. Of the features I use most in third-party email clients, Mail’s biggest shortcoming is its clunky implementation of deep links.

I constantly drop links to emails in my notes and tasks to quickly access important contextual information. Mimestream offers Gmail URLs and Spark can create its own app-specific and web URLs directly in those apps’ user interfaces.

In contrast, on iOS and iPadOS, you can only link to a Mail message by dragging it out of Mail into another app’s text field. I’ll take it, but I’d prefer if I could quickly generate a link from the share sheet or with shortcuts instead. The situation on the Mac isn’t much better, forcing users to resort to AppleScript to construct a URL that points to a Mail message.

With weeks of Ventura testing ahead of me, I decided to see what I could do to improve the situation. The result isn’t perfect: I still have no choice on iOS and iPadOS but to drag and drop messages. However, I improved the experience on Mac by using a combination of AppleScript and a shortcut that I trigger using Raycast to link the subject of a Mail message to its URL. For more context, my shortcut also adds the sender’s name.

At the start of this project, I was aware of an AppleScript that had been circulating in automation forums for years and written by David Sparks which is based on Python. The problem is that Python is no longer pre-installed on the Mac. It’s not difficult to installbut I was wondering if there was an easier way to create message links that didn’t include a Python dependency.

Turns out what I decided to do is pretty simple. The seed of the script I wrote started with a story Federico wrote about how he used Mail’s URL scheme in the iOS 7 days, which relied on a script that John Gruber published on Daring Fireball in 2007. With this script as a guide, it didn’t take long to create one of my own using Mail’s built-in AppleScript support and a single-action shortcut that doesn’t require Python.

Mail has extensive AppleScript support, making it easy to access the components of a message. The first step is to define the variable _msg to the selected message in Mail. Next, _messageURL takes the message’s message ID and drops it into the URL scheme that will open it in the Mail app, regardless of where it’s filed. Next, I access the subject of the message and its sender. Then I pull the sender variable name using extract name from because the variable includes the person’s name and their email address, but all I want is the person’s name.

The final step is to put it all together into a single string of text in Markdown format and copy it to the clipboard using the AppleScript syntax for creating strings. The script is then embedded into a single-action shortcut that uses the Run AppleScript action to trigger it. Now I can open Mail alongside a note-taking app or task manager and drop a link to the message and its sender by calling Raycast and typing the alias I assigned to the shortcut (mlink) or the keyboard shortcut I gave it (⌃M). Additionally, the links I create work on iOS, iPadOS, and macOS.

The My Mail Link shortcut, which you can download below, has improved the way I link messages on my Mac. However, since I have to rely on drag and drop on iPhone and iPad, it’s not perfect. What I really want is a better solution from Apple. Ventura improves the interoperability of system applications across platforms and through collaboration with other users. The next step should be deeper integration at the content level, something I’d like to think is foreshadowed by Focus Filters, Apple’s new way of contextually displaying calendars, mailboxes, groups of tabs and other content based on your iOS, iPadOS and macOS. Focus settings. Hopefully, a user-friendly deep linking solution from Apple will emerge in the future. Until then, though, I’ll use Mail Link on the Mac and drag and drop on the iPhone and iPad.

You can download Mail Link here.

Share.

About Author

Comments are closed.