Last active
April 17, 2019 17:11
-
-
Save dschaehi/45af4615c7f94da1d0cdfa6cbaf1de61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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