is there any way to modify the script to yield the subject line as a clickable link.
example: [Grab a bestseller for just 99p] (the subject) which if clicked on would go to the email link message:%3C4Q80.A9LF.943CHBAW78.20200125123837534@emails.pocketmags.com%3E
thanks in advance for your time and help !
(*
Returns a link to the first selected Apple Mail message
*)
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)
return "message://%3C" & (_msgID) & "%3E"
end if
end tell
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
So I guess it depends where you’d be using this link whether the result would be clickable.
thank you very much for your script
It works in Script Editor but not in Evernote (or Bear) where I would be using it.
thanks again very much for your time and effort.
I searched the Internet and am surprised that there is not more interest or demand for such a script which seems rather essential to me.
Can I ask how you were triggering the script and what you were doing with the result?
The script above was just returning the Markdown formatted link. not putting it on the clipboard or outputting it for use from what I can see.
The Evernote scripts you linked to were using HTML based link formatting (rather than the Markdown links above). Bear should support both HTML and Markdown I think for links.
My current suspicion is that you didn’t have anything to output the link. Just to build a Markdown link,
you have an excellent point and I am at fault.
I assumed that the output would be in the clipboard.
I had no idea that a script could create a link … and that’s it.
How should I copy it to the clipboard <’
thanks very much for your comment.
Is anyone else getting this error when running @MacSparky’s brilliant script for linking to an email? This seems to be the result of something in Python breaking after Monterey 12.3.
Mail got an error: sh: /usr/bin/python: No such file or directory
And, if you use Homebrew to install Python3, you need to change the script to the following (if you want the Markdown link on your clipboard):
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/python3 -c 'import sys, urllib.parse; print (urllib.parse.quote(sys.argv[1]))' " & (message id of _msg)
set _msgSubject to subject of _msg
set messageLink to "[" & _msgSubject & "](message://%3C" & (_msgID) & "%3E)"
set the clipboard to messageLink
end if
end tell