Copying and saving clipboard to text not giving expected result

I have made a macro for copying a table in InDesign and then saving the data to a text file.

The first very simple macro (see below) did not work. Every cell becomes a new line when saving the text-file.
Bechmann - Export marked table to text file - Linebreak instead of TAB.kmmacros (4.0 KB)


But the clipboard contains \t between cells. I can not see why it becomes a line break in the result.
Is this a bug or some expected behaviour I can not see.

Files for help to solve this:
Clipboard: (made with this macro)

I got it to work with this macro.
Bechmann - Export marked table to text file - Works.kmmacros (5.1 KB)

My guess is you are experiencing a case where the different “flavors” of clipboard data contain different text.

Each clipboard is made up of a multitude of flavors, multiple variants of plain text, multiple variants fo rich/formatted text, maybe even some images, pdfs, and private flavors.

Keyboard Maestro will use a plain text flavor if you ask for plain text (as you do in the actions you show), or a rich text flavor if you appropriate (eg if you use Insert Styled Text by pasting with the %SystemClipboard% token).

When you paste, the target application will choose whatever flavor it thinks is best suited to the location.

Normally the if you take a rich text flavor and remove the styling on it to get plain text you would end up with the same text as the plain text flavors. But applications are sometimes dumb and put different text in the styled flavor to that in the plain flavors. And that is my guess as to why you are seeing different results.

You can try an action like this:

Set Clipboard to Styled Text “%SystemClipboard%”


Set Clipboard to Plain Text “%SystemClipboard%”

That will have Keyboard Maestro read the plain or rich text flavor from the clipboard, and then write it back to the clipboard - but when it writes it back all the text flavors will have correctly matching text.

I used the Clipboard Viewer macro to extract the clipboards flavors.

And UTF 8 plain text is this:
"public.utf8-plain-text-string": "Stålmøtrik Din 934 Sorte\r- kvalitet 8\t\t\t\t\\tTekst\tAntal pr. pk.\tM x længde i mm\tGevindstigning\rBC 1803000-100\tSTÅLMØTRIK 3 MM SORTE \t100\tM3 \t0,50\rBC 1804000-100\tSTÅLMØTRIK 4 MM SORTE \t100\tM4\t0,70\rBC 1805000-100\tSTÅLMØTRIK 5 MM SORTE \t100\tM5\t0,80\rBC 1806000-100\tSTÅLMØTRIK 6 MM SORTE \t100\tM6\t1,00\r",

And then I would expect Keyboard Maestro to save this to the text file.
But all \t becomes line breaks. This is what I do not understand.

I have now tried both your suggestions, but it still gives me line breaks instead of tab in the output.