Grabbing info from same line but other side of table to KM Variable?


Does anybody know how I can get the name from the same line and save to DL as a variable? if you could post the action that would be very helpful.

What does the source look like? Not an image, what is actually in the Mail Content variable?

Your First Name:
Your Middle Name:
Your Last Name:

Keyboard Maestro Actions.kmactions (897 B)

1 Like

How do I differentiate each variable?

Your First Name:
Your Middle Name:
Your Last Name:
Telephone number:
Your Email address:
Your Date of Birth:
Address Line 1:
Address Line 2:
Address Line 3:
Post Code:

Like all such requests, if you don't post the different possible inputs, then you're not going to get a complete solution.

If you have lots of different variants, then you'll need to use a search for each field.

You probably need a negative lookbehind test to avoid lines that have colons at the end. Oh, and a Possessive match qualifier.

This should work. Some notes:

  • Requires 10.11+ because I was slack and used the \h horizontal space metacharacters (see this discussion).
  • The search will fail, so notification and aborting needs to be turned off, and the variable needs be set to the default (empty string?) before the search.
  • The regex uses a possessive match (.++) to match all the characters on the line and not backtrack from there.
  • The regex uses a negative lookbehind assertion to abort if the line ends in the colon (which means none of your values can have lines that end in a colon).
  • There is an initial search & replace to get rid of trailing horizontal space to ensure the colon is always the last character on the line if it is there.
  • Repeat the last two actions for each key and variable.

Keyboard Maestro Actions.kmactions (2.1 KB)


which line in this action separates it? using a single action is preferred.


Problem solved :slight_smile:

Peter, I’m wondering if this would be a good use case for the new Dictionaries (KM Wiki) feature?

You certainly could use a dictionary for this purpose. Something along the lines of:

  • Comment: Clear the dictionary
  • For each Key in Dictionary “Results”
    • Set Dictionary “Results” Key %Variable%Key% to “”
  • Comment: Repeat this for each possible search
  • Search for first case
  • If Action Result is OK
    • Set Dictionary “Results” key “This Key” Value %Variable%This Match%

It depends on what you want to do next as to whether that is better or worse than a set of variables.

1 Like