Skip to content

Instantly share code, notes, and snippets.

@duncangh
Created March 23, 2020 22:26
Show Gist options
  • Save duncangh/0ba31b88ac8183f059538ab38ad1d225 to your computer and use it in GitHub Desktop.
Save duncangh/0ba31b88ac8183f059538ab38ad1d225 to your computer and use it in GitHub Desktop.
import subprocess
def write_to_clipboard(output):
process = subprocess.Popen(
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(output.encode('utf-8'))
#How to read a Unicode string from the Mac clipboard:
import subprocess
def read_from_clipboard():
return subprocess.check_output(
'pbpaste', env={'LANG': 'en_US.UTF-8'}).decode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment