1

In macOS you can obtain (explained here how) the URL to a specific email. So that if you click to the that URL, or you paste it into a browser search bar, that specific email will open in Mail.app.

Such a URL looks like this message://<CALoR5A+vANPG9eCcHRHnO@mail.gmail.com>

In Catalina I could use the command open to reach such a URL from the command line, by typing

open -a "Mail.app" "message://<CALoR5A+vANPG9eCcHRHnO@mail.gmail.com>"

But with BigSur if I try that I get the following error

The file /Users/macbook/message:/<CALoR5A+vANPG9eCcHRHnO@mail.gmail.com> does not exist.

This behavior seems to be related to a bug in BigSur.

Two question

  1. Do you know if the open command can still be used for that task somehow?

  2. Alternatively, I am looking for a workaround. It must be possible to achieve the behavior I am expecting because if you past a message:// URL in Chrome, Safari or in a rich text editor which supports hyperlinks, it is correctly handled.

I have tried, unsuccessfully many approaches.

Swift script

import AppKit
NSWorkspace.shared.open(URL(string: "message://<CALoR5A+vANPG9eCcHRHnO@mail.gmail.com>")!)

The URL is nil.

Apple Script

tell application "Mail"
    activate
    open location "message://<CALoR5A+vANPG9eCcHRHnO@mail.gmail.com>"
end tell

I am not sure if the above code would have worked in Catalina, I just know that in my case it just opens the Mail app without doing anything else.

Using Chrome

If you paste a message:// URL in Chrome it asks you to confirm that you want to open it in the Mail app. This can be overridden with the following command: defaults write com.google.Chrome URLWhitelist -array 'message://*'

Asking Chrome to open a URL for you looks like a easier task, but still the command open -a "Google Chrome" "message://<CALoR5A+vANPG9eCcHRHnO@mail.gmail.com>" fails with an error similar to the one shown before:

LoR5A+vANPG9eCcHRHnO@mail.gmail.com>"
The file /Users/macbook/message:/<CALoR5A+vANPG9eCcHRHnO@mail.gmail.com> does not exist.

Any ideas?

Nisba
  • 3,210
  • 2
  • 27
  • 46

1 Answers1

1

I found the reason why the open command does not work anymore: the angular brackets need to be escaped.

The following command does not work

open -a "Google Chrome.app" "message:<CALoR5A+vANPG9eCcHRHnO_fNTrzgbMpX666oBGxHWsRaXb5@mail.gmail.com>"

The following one opens the Mail app, which will complain that the URL is broken

open -a "Google Chrome.app" "message:CALoR5A+vANPG9eCcHRHnO_fNTrzgbMpX666oBGxHWsRaXb5@mail.gmail.com>"

Finally, by escaping the URL, it works:

open -a "Google Chrome.app" "message:%3CCALoR5A%2BvANPG9eCcHRHnO_fNTrzgbMpX666oBGxHWsRaXb5%40mail.gmail.com%3E"

Note, you can make the URL start with message: or message://, it does not matter.

Nisba
  • 3,210
  • 2
  • 27
  • 46