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

I wish to use a macro to prompt to capture various text items, those that are relevant here:

Party 1
Party 2

And I wish to output it a format as follows: Party 1 v. Party 2. Party 1 and Party in italics.

However, sometimes there is no Party 2, so the output would just be Party 1. Party 1 in italics.

The above is not a problem (using a Prompt for User Input, and then If Any Conditions Met Execute Actions).

However, the issue I am having difficulty with is that sometimes I wish to run the macro in a number of apps that support MultiMarkdown and sometimes in something such as Word or LibreOffice. If I set the output to paste as style text, and I use, eg, MultiMarkDown composer, then the styled text is just paste in as plain text and Party 1 and Party 2 are not in italic, and if I enter the MultiMarkdown code for italic (*), and paste into Word/LibreOffice, then the code is not recognised for italic.

There are quite a number of alternatives:

  1. There is no Party 2 but the application used is nvAlt
  2. There is no Party 2 but the application used is MultiMarkdown Composer
  3. There is no Party 2 but the application used is Byword
  4. 4.1. There is Party 1 and Party 2 but the application used is nvAlt
  5. There is Party 1 and Party 2 but the application used is MultiMarkdown Composer
  6. There is Party 1 and Party 2 but the application used is Byword
  7. There is no Party 2 but the application used is Word
  8. There is no Party 2 but the application used is LibreOffice
  9. etc etc

Which combination of Keyboard Maestro commands should I be using to achieve what I want? Any help would be gratefully received.

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

There really is only four cases. Either the application supports markdown or not, and either there is a second party or not.

So start off by setting a variable “Use Markdown” to 0 or 1 depending on the target application, something like:

  • If any of the following is true
    • application is nvAlt
    • application is MultiMarkdown Composer
    • application is Byword
  • then set variable “Use Markdown” to 1
  • else set variable “Use Markdown” to 0

Then set variable Party 1 to party 1, and Party 2 to party 2 or empty (nothing).

Now you have a relatively simple sequence to process it:

  • If Party 2 is empty
    • If variable Use Markdown is 1
      • Insert Text “•%Variable%Party 1%•”
    • else Insert Styled Text “%Variable%Party 1%
  • else
    • If variable Use Markdown is 1
      • Insert Text “•%Variable%Party 1%• v. •%Variable%Party 2%•”
    • else Insert Styled Text “%Variable%Party 1% v. %Variable%Party 2%

Note: I’ve used bullets when there would be markdown asterisks, and asterisks to italic the styled text, given its tricky to try to write about markdown in markdown.

The alternative approach, and an approach that you would need to use if you have mode options (for example if there could be a third party, and sometimes you needed to use “vs” instead of “v.”, etc). Eventually it becomes too cumbersome. In that case what I would do would be to find a way to generate one for and process it into the other form. Perhaps something like this:

  • if Party 2 is empty

    • Set Named Clipboard Result to “•%Variable%Party 1%•
  • else Set Named Clipboard Result to “•%Variable%Party 1%• v. •%Variable%Party 1%•

  • if variable Use Markdown is 1

    • Insert Text “%NamedClipboard%Result%”
  • else

    • Search and Replace Named Clipboard Result “•” with “”
    • Paste Named Clipboard Result

So basically, create a named clipboard with italic styled markdown, and then either insert it as plain text or remove the asterisks and then paste it in as styled text.

JmichaelTX and Peter,

Thank you very much for your responses.

Peter’s first solution is exactly what I needed.