Created
June 21, 2018 15:00
-
-
Save nickymarino/e82b3efc9317c91357af351c1c9f354a to your computer and use it in GitHub Desktop.
Copy to clipboard using python
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 sys | |
import subprocess | |
def copy(string): | |
commands = {'win32': 'clip', | |
'cygwin': 'clip', | |
'darwin': 'pbcopy', | |
} | |
currentPlatform = sys.platform | |
if currentPlatform not in commands: | |
raise KeyError('Platform not supported') | |
copyCommand = commands[currentPlatform] | |
subprocess.Popen([copyCommand], stdin=subprocess.PIPE, encoding='utf8').communicate(string) | |
if __name__ == '__main__': | |
copy('testing the clipboard :)') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment