MD Link to selected email (when Apple Mail not in focus)

Hello,
I use the following macro to insert a Markdown link to the currently selected email in Apple Mail (I use it to insert the link into Bear Notes which are in Markdown format).
It is not elegant having to activate Mail which flashes on the screen then return to last application.

thank you very much !

The Markdown Link Copy As executable macro in my macro is taken from
Copy as Markdown Link - Macro Library - Keyboard Maestro Discourse


Insert Markdown LINK to currently selected email.kmmacros (44.8 KB)

more elegant

 
 
Just ⌘V after:

?

1 Like

hello @ComplexPoint

I think that I offended you and I apologize profusely. My question was poorly formulated and gives the impression that I do not give you proper credit for a brilliant macro that I use many time every day.

My question is: suppose I am working in a markdown Bear note and while in Bear I want to insert a link to the currently selected email in apple mail, is there any way to do this without exiting bear β†’ activating Mail β†’ triggering your excellent macro β†’ coming back to Bear β†’ paste Markdown link. It's the navigating apps part that I want to try to avoid.

You have been a huge help over the years, on many occasions, and once again, I am very sorry.

No offence at all, and no apologies required :slight_smile:

Just unclear about what problem you were trying to solve,
and what the question really was.

I will offer up an AppleScript that I use in other macros, slightly modified to return a link. Caution: I did not write this myself, it's regurgitated crud from an AI, but it seems to work fine.

If you have multiple items selected, it returns the first of them.

tell application "Mail"
	set selectedMessages to selection
	if selectedMessages is {} then
		return "No message selected"
	else
		set theMessage to item 1 of selectedMessages
		set messageURL to "message://%3c" & message id of theMessage & "%3e"
		return messageURL
	end if
end tell

You'll then have to invoke @ComplexPoint's macro, or do whatever, to get it into a markdown link format.

-rob.

1 Like

@ComplexPoint's macro designed to create a markdown (or similar) link to the selected item in the frontmost app -- you want to get a link to the selected item in Mail when Mail isn't frontmost. You can do that without activating Mail by using AppleScript/JXA (an option not available for many of the apps Rob's macros can handle), as @griffman's shown.

Luckily, Rob's used JXA to do the hard work of getting/formatting the link text in the "com.apple.mail" macro in the "MD link tools" Macro Group -- and it doesn't require Mail to be frontmost! It saves the text in the global variable mdLink, so all you need to do is execute that macro then insert the contents of mdLink:

2 Likes

works perfectly. Exactly what I was looking for. Thanks very much and thanks again @ComplexPoint for the original copy as markdown link macro.

thank you very much. Sorry I will go with @Nige_S 's soution

No need to apologize, the work was already done and @Nige_S showed a much better way to get it!

-rob.

1 Like