BigSur open command does not handle message:// URLs anymore, workarounds?

202 Views Asked by At

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://<[email protected]>

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

open -a "Mail.app" "message://<[email protected]>"

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

The file /Users/macbook/message:/<[email protected]> 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://<[email protected]>")!)

The URL is nil.

Apple Script

tell application "Mail"
    activate
    open location "message://<[email protected]>"
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://<[email protected]>" fails with an error similar to the one shown before:

[email protected]>"
The file /Users/macbook/message:/<[email protected]> does not exist.

Any ideas?

1

There are 1 best solutions below

0
On

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:<[email protected]>"

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

open -a "Google Chrome.app" "message:[email protected]>"

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.