Created
October 26, 2025 22:35
-
-
Save khelwood/26ee0d38353788b59d7a79244af51ba6 to your computer and use it in GitHub Desktop.
This is the clipboard lib that I use on macs
This file contains hidden or 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
| import subprocess | |
| if str is bytes: | |
| def copy(text): | |
| p = subprocess.Popen(['pbcopy', 'w'], | |
| stdin=subprocess.PIPE, close_fds=True) | |
| p.communicate(input=str(text)) | |
| def paste(): | |
| p = subprocess.Popen(['pbpaste', 'r'], | |
| stdout=subprocess.PIPE, close_fds=True) | |
| stdout, stderr = p.communicate() | |
| return stdout | |
| else: | |
| def copy(text): | |
| p = subprocess.Popen(['pbcopy', 'w'], | |
| stdin=subprocess.PIPE, close_fds=True) | |
| p.communicate(input=text.encode('utf-8')) | |
| def paste(): | |
| p = subprocess.Popen(['pbpaste', 'r'], | |
| stdout=subprocess.PIPE, close_fds=True) | |
| stdout, stderr = p.communicate() | |
| return stdout.decode('utf-8') | |
| def copylines(lines): | |
| copy('\n'.join(map(str, lines))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment