How Do I copy URL To Open a Mac (Apple) Email to clipboard?

This must be a common request but I don't find any macro to do so in the forum.
thanks in advance for your time and help

dumb question, what's a Mac Email URL?

1 Like

thank you for reading my post.
If I drag and drop an email from Mail into any editor, for example Evernote, I end up with a functional mailbox independent link to that email.
I would like to capture that link directly in Mail (which I probably wrongly call email URL) and paste it wherever I want.
thanks again

ah! neat, just learned something today :smiley:

Sounds like a deep link.

Don't know the answer, but in a quick web search found this post with some Applescript to copy the URL to your clipboard, hope it helps:

1 Like

For future reference, this is known as a URL Scheme, which tells another app on your Mac to perform some action, like open a specific record.

2 Likes

another option by MacSparky

2 Likes

thank you

thanks. Script does not work.

Great idea ! thank you so much !!

I copied the MacSparky script into typinator with an abbreviation, and works like a charm in all apps. I don't need to be in mail. The URL copied is that of the email currently highlighted in Mail (in the background).

Just for the sake of discussion, ideally, the end result would look like what I see if I drag and drop an email from mail into Bear where you see the subject of the email which is an active link to the email itself.
I say this because with the MacSparky script, you end up with a long cryptic link with no idea of the content.

Would you have any idea if the script could be modified to create the result below ?

thanks again very much

image

in case it's of use to you, this is the script to capture the active tab of Chrome (even if Chrome is in the background). I find it very useful

tell application "Google Chrome"
    get URL of active tab of first window
end tell

If you are asking to return a Markdown Link instead of the URL, then this script should do the job:

tell application "Mail"
  set _msgs to selected messages of message viewer 0
  if (_msgs is not equal to missing value) then
    set _msg to first item of _msgs
    
    ##JMTX ADD:  Get EMail Subject ###
    set _msgSubject to subject of _msg
    set _msgID to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & (message id of _msg)
  end if
end tell

##JMTX CHG:  Create URL and Markdown Link to EMail ##
set _msgURL to "message://%3C" & (_msgID) & "%3E" -- URL
set _msgMD to "[" & _msgSubject & "](" & _msgURL & ")" -- Markdown link

return _msgMD
1 Like

thank you for your script.

Your script works perfectly in script editor but yields nothing in Evernote (my focus of interest) or Bear (which is Markdown).

I did not think you were going to write a script so I asked the question on the automator forum, got one reply with a script (below) which does not work.

In addition, my Typinator abbreviation no longer yields a clickable link in Evernote, contrary to yesterday.

Today, drag and drop from Mail to Evernote only works for personal email. Links to email notifications from the KBM forum are broken.

I think that it has something to do with Mail database indexing. Mail is very buggy. I know it from having wasted time configuring smart mailboxes which do not refresh.

It is very frustrating.


tell application "Mail"
	
	set _msgs to selected messages of message viewer 0
	
	if (_msgs is not equal to missing value) then
		
		set _msg to first item of _msgs
		
		set _msgID to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & (message id of _msg)

		set _msgSubject to subject of _msg
		
		return "[" & _msgSubject & "](message://%3C" & (_msgID) & "%3E)"
		
	end if
	
end tell

@janov @hello @JMichaelTX

can find a superb script here

REQUEST: Ability to link to emails in Mac Mail - Evernote for Mac Requests (Versions 7.14 and under) - Evernote User Forum

this is the script:

Moderator: Script from
https://discussion.evernote.com/topic/18181-request-ability-to-link-to-emails-in-mac-mail/#comment-398956

set _links to {}
set _Titles to {}
set _dates to {}

tell application "Mail"
  set _sel to get selection
  repeat with _msg in _sel
    set _messageURL to "message:\\%3c" & _msg's message id & "%3e"
    set end of _links to _messageURL
    set myTitle to the subject of _msg
    set end of _Titles to myTitle
    set theDate to date received of _msg
    set theString to ((time string of theDate) & " " & (day of theDate) as string) & " " & (month of theDate) as string
    set theAuthor to sender of _msg
    set theString to theString & " - " & theAuthor & " -   "
    set end of _dates to theString
  end repeat
  set AppleScript's text item delimiters to return
  set the clipboard to (_links as string)
end tell

tell application "Evernote"
  activate
  try
    set theNotes to selection
    repeat with thisNote in theNotes
      set theHTML to HTML content of thisNote
      repeat with n from 1 to count of _links
        set _messageURL to item n of _links
        set theTitle to item n of _Titles
        set theDate to item n of _dates
        -- append thisNote html "<div><b><a href=" & _messageURL & ">" & theTitle & "</a></b></div>"
        set theHTML to "<div><b>" & theDate & "   <a href=" & _messageURL & ">" & theTitle & "</a></b></div>" & theHTML
        set HTML content of thisNote to theHTML
      end repeat
    end repeat
  end try
end tell
1 Like

in reference to my comment about drag and drop personal vs forum emails, all the links were functional after a few evernote syncs, which is apparently know according to evernote forums

My script does exactly what I stated:

So, the reasons it is not working for you in Evernote are:

  1. The script returns, but does NOT paste the MD link.
  2. Evernote does NOT support markdown.
  3. Evernote does NOT support custom URL schemes, like the one for Apple Mail

I tested my script by creating the MD link in Script Debugger 7, copied the MD link in the results panel, and pasting into the MacDown app. I then clicked on the Macdown rendered link and it opened the message in Mail.

@ronald, when you post a script, please post it using the Forum Code Block.
Otherwise, you can end up with a lot of extra characters, like you did, when you post the script directly as copied from the Evernote Forum, which looked like this:

**set**  _links  **to**  {}

**set**  _Titles  **to**  {}

**set**  _dates  **to**  {}

Please confirm that I replaced your script with the proper source as shown above.

2 Likes

When I test this script in Script Debugger 7, it did create a hyperlink in Evernote, but the link did not work -- when I clicked on it, it did nothing.

Note that the thread you copied the script from was posted in 2016. At that time there was a very different version of Evernote Mac.

I'm running Evernote 7.13 (458080) on macOS 10.14.6 (Mojave), which is just one minor version prior to the latest Version 7.14.

1 Like

sorry for the bungle. yes you did replace correctly. I will keep code block in mind

I have been using the email link script many times in the past 24 hours and it has never failed (link functional).

Evernote version below. Mojave latest update.

Results are superb.

I found 2 issues in the forum if the link does not work (it worked when I had problems with typinator script):

  • evernote resync a few times, changes notes and return to initial note
  • Mail quit and restart to reindex database (this has also worked for me with old script). The logic is that the link can't find the email which is not properly indexed.

Note a little trick I use : in the test email below, I created a macro to add a delete tag which makes it easy to subsequently delete the email. It is faster, more convenient (can be done from email body) and less risky IMO than deleting the conventional way.

image


hi, I would like to know if someone has solved a similar problem