Help sought in how to structure a macro (and which commands to use)

There may be other ways to achieve this, but the only way I know is to use a script, like AppleScript or JXA.

I have done something similar, putting two formats on the clipboard:

  1. Rich text for hyperlink
  2. Plain text for Markdown link

Then, when you paste into a rich text document, like Word, it will paste #1. When you paste into a plain text document (like this forum), it will paste #2.

In the script, the process is:

  1. Create the HTML code to format your text
  2. Copy this to the clipboard, and convert to Rich Text in the process
  3. Read the clipboard to get only the rich text
  4. Create a record with rich text and plain text
  5. Copy this record to the clipboard.

See this example:
Macro: Set Clipboard to RTF Hyperlink & Plain Text MD Link