Copy Umlauts to clipboard

Currently I’m trying to push a piece of text like below

To the clipboard using pbpaste -Prefer txt.
But this way doesn’t respect Umlauts so I have to find replace Umlauts with Ae, oe, ss, ect.
Of course I prefer right looking characters instead some alternatives.

I have to use pbpaste -Prefer txt, otherwise things would be easy using a simple copy - paste.

I use this via ssh and it works for äüö etc.:

Hi Joy.

As you’ll have seen from db123’s reply, the command for pushing to the clipboard is pbcopy. By default, it and pbpaste use C encoding for text unless unless told otherwise. This doesn’t appear to matter if you’re using both commands:

set txt to "Äbc
Cdë
Efß
Janáček
Martinů
Łódź"

do shell script "echo " & quoted form of txt & " | pbcopy" -- To clipboard.
do shell script "pbpaste" -- From clipboard

But if you need to use pbcopy and then possibly some other method to paste the result from the clipboard, you should set the “LANG” environment variable to some UTF-8 setting. I don’t think it matters which actual language is specified. I’ve used en_GB here:

set txt to "Äbc
Cdë
Efß
Janáček
Martinů
Łódź"

do shell script "echo " & quoted form of txt & " | LANG=en_GB.UTF-8 pbcopy" -- To clipboard.
do shell script "LANG=en_GB.UTF-8 pbpaste" -- From clipboard
-- Or:
the clipboard
-- Or paste manually.

I had used this for retrieving and posting the clipboard between iPhone and Mac via Shortcuts (and a SSH-action) when the iCloud clipboard did not exist yet. At that time I couldn’t get it to work any other way on a German system.

Thanks to @Nigel Garvey and @db123 for sharing the experience. I experimented a little here and noticed that it doesn’t matter which method you use to copy the text to the clipboard. It only matters how you get (or paste) the text from the clipboard.


set the clipboard to ¬
	"Äbc
Cdë
Efß
Janáček
Martinů
Łódź" -- or, copy this text manually

the clipboard as text

-- or
do shell script "export __CF_USER_TEXT_ENCODING=0x1F5:0x8000100:0x8000100;pbpaste"

-- or
do shell script "LANG=en_GB.UTF-8 pbpaste -Prefer txt"

-- or, simply
do shell script "LANG=en_GB.UTF-8 pbpaste"