Thank you @iPersuade and of course @MacSparky for the great script to use with apple mail.
Since I’m not a TextExpander user, but was searching a solution for linking directly to mails a long time ago (I gave up until I saw your post and got motivated again).
Now I adapted the script to directly add all selected (not just the first) mail as links with their subject as title for the link to Drafts or Todoist. This works on the Mac with the URL schemes of the two apps.
If someone needs them here you go:
add selected mails to todoist:
tell application "Mail"
set _msgs to selected messages of message viewer 0
if (_msgs is not equal to missing value) then
repeat with _msg in _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 this_subject to (subject of _msg) as Unicode text
set encoded_subject to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of this_subject
open location "todoist://addtask?content=[" & (encoded_subject) & "](message://%3C" & (_msgID) & "%3E)"
# add delay and press return to give todoist enough time to process the input
tell application "System Events"
delay 0.3
keystroke return
delay 0.3
end tell
end repeat
end if
end tell
add selected mails to Drafts:
tell application "Mail"
set _msgs to selected messages of message viewer 0
if (_msgs is not equal to missing value) then
repeat with _msg in _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 this_subject to (subject of _msg) as Unicode text
# delay 1
set encoded_subject to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of this_subject
open location "drafts5://x-callback-url/create?text=(" & (encoded_subject) & ")[message://%3C" & (_msgID) & "%3E]"
end repeat
end if
end tell