Workflow suggestion for filling templates from table?

I need your often so helpful advice: I would like to create a solution that is as simple as possible and includes the following:

  • Data (text) is entered manually in a table. The table has a maximum of 8 columns and 10-50 rows, depending on the project. Some rows might contain multiline text. Special characters like () {} β€œβ€ / | are common as part of the strings.
  • Keyboard Maestro fills a text template from the data in the table. Whenever the action is executed, a new row is processed into a template which is then pasted. This is part of a larger workflow.

Example table:

Description en Source Date Author Permission License
Horse and a pond own reproduction 1822 Magnus Torstenson not required {{Cc-zero}}
Fish and forest own reproduction 1931 SΓΆren McCave not required {{Cc-zero}}

Example template

{{Information
|Description=
|Source=
|Date=
|Author=
|Permission=
|other_versions=
}}

== {{int:license-header}} ==

Expected result:

{{Information
|Description=Horse and a pond
|Source=own reproduction
|Date=1822
|Author=Magnus Torstenson
|Permission=not required
|other_versions=
}}

== {{int:license-header}} ==
{{Cc-zero}}

Regarding the table part, I have Numbers and TableFlip available. Whenever another application is recommendable, just tell me, but I won't buy Excel for this.

How would you approach this problem (please basic advice, don’t spend your valuable time writing a macro for me)?

Thanks a lot.

I'm afraid this more a macro than just advise.

First thing I would advise you is to structure your input file. What I did is making it a TSV file (tab separated values). This allows you to figure out where the fields start and end.

I assumed that the word en after the word Description was an error.
You do have other options like using separators that do not occur, e.g. a bar "|".

And I then read the file and copy it on the clipboard.

As you can see I changed the template slightly. The values '{name}' will be replaced by the corresponding field in the file. So the column names in the 'TSV' file must match the names you use in the template.

image

I want to read the headers (columns) from the file. So I initialize the variable tmp headers to 0.

I then iterate over each line on the clipboard. Remember this is the contents of the TSV file. Each line is stored in the variable tmp line.

The variable tmp headers contains 0 so the value of the first line is stored in the variable tmp headers.

The on the next iteration in the for loop we will see a content line.

I am accessing the variable tmp headers as an array.

There are two things to notice here. Field zero of the array contains the number of values in the array, i.e. the number of headers and it will have the number 6. This value is assigned to the variable tmp header index.
The second thing to notice is that \t after the closing square bracket. This tells KBM that I use the tab as a separator when I access the variable.

The next step is to iterate over each header:

image

The next step is to extract the name of the header from the tmp headers variable:

and the content of the variable fron the tmp line variable:

The values are now used to replace the template values:

And then decrement the variable tmp header index.

Then finally this is the result:

image

1 Like

For clarity -- are you saying that the data is already in the table, and you want to use KM to extract it row by row to use somewhere else?

If so, can the table be changed in the process -- deleting rows, for example? Are you going to process the whole table in one go, or come back to it after a period of time? Is there just the one table, or many? Asking because the trickiest part might be keeping track of "next row to process"!

Thanks for your time and effort, it is much appreciated.

I built the macro according to your input, but likely the flow of the program is flawed due to an error in the grouping of actions.

Please have a look here:

Commons: Tabelle β†’ Dateiinformation Macro (v11.0.3)

Commons- Tabelle β†’ Dateiinformation.kmmacros (7.5 KB)

Thank you.

Yes.

These are good questions. The table can be altered in the process. It is just one table. Going back to the workflow after interrupting it would be a nice to have.

I think it is easier for me to just share the macro I wrote.

TSV processor.kmmacros (11.3 KB)

You should be able to take this and adjust to your needs.

Thank you very much!

I added a second line to my initial example, however when I run the macro, I get the same (first content line) three times. Did it work for you with more than one content line?

You have to move the initialization of the template inside the first loop that iterates over the lines.

Thank you, this solves this issue!