Skip to content

Instantly share code, notes, and snippets.

@dschaehi
Last active April 17, 2019 17:11
Show Gist options
  • Save dschaehi/45af4615c7f94da1d0cdfa6cbaf1de61 to your computer and use it in GitHub Desktop.
Save dschaehi/45af4615c7f94da1d0cdfa6cbaf1de61 to your computer and use it in GitHub Desktop.
#!/usr/local/miniconda3/bin/python
# A snippet for reading a Unicode string from clipboard, convert the string to one that is ASCII compatible, and then paste it to the clipboard. This converts for example "ß" to "ss"..
# The code is based on the answer https://stackoverflow.com/a/25802742/3706018.
import pasteboard
import subprocess
from unidecode import unidecode
pb = pasteboard.Pasteboard()
asciidata = unidecode(pb.get_contents())
def write_to_clipboard(output):
process = subprocess.Popen(
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(output.encode('utf-8'))
write_to_clipboard(asciidata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment