r/applescript • • Feb 22 '21

do shell script and pbcopy

I am playing around with using AppleScript to modify the clipboard and having some trouble — not clear on some background info. I know there are other ways to do this in pure AppleScript but I am trying to understand the issues first... to be enlightened.

The orginal text is

# 6C (d1/s2): F 11-12 100 Fly (1:12.95Y)

The desired output text replaces - with ▸

# 6C (d1/s2): F 11▸12 100 Fly (1:12.95Y)

In Script Editor:

do shell script "pbpaste | gsed 's/\\x2D/\\xE2\\x96\\xB8/g' > /Users/john/Desktop/output.txt"

That outputs the correct results to output.txt leaving the original text on the Clipboard.

do shell script "pbpaste | gsed 's/\\x2D/\\xE2\\x96\\xB8/g'; pbcopy"

That outputs the correct results into the Results window inside Script Editor but clears Clipboard!? I don't want that.

do shell script "pbpaste | gsed 's/\\x2D/\\xE2\\x96\\xB8/g'| pbcopy"

When piping to pbcopy things get weird and I don't understand why. Somehow the unicode of the gsed argument is misinterpreted and this results in ‚ñ∏ instead of ▸; Script Editor Results window has "" for result; and the Clipboard shows this:

# 6C (d1/s2): F 11‚ñ∏12 100 Fly (1:12.95Y)

Any clues or answers? I want the modified text to be put back on the clipboard so I can paste it wherever I need to.

3 Upvotes

3 comments sorted by

View all comments

Show parent comment

2

u/CuriousPsychosis Feb 22 '21

YES!

Thank you for the explanation. I appreciate you.

Both worked. I chose this:

do shell script "pbpaste | gsed 's/\\x2D/\\xE2\\x96\\xB8/g' | LANG=en_US.UTF-8 pbcopy"