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
Do you know if the
open
command can still be used for that task somehow?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?
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
The following one opens the Mail app, which will complain that the URL is broken
Finally, by escaping the URL, it works:
Note, you can make the URL start with
message:
ormessage://
, it does not matter.