Skip to content

Instantly share code, notes, and snippets.

@nickymarino
Created June 21, 2018 15:00
Show Gist options
  • Save nickymarino/e82b3efc9317c91357af351c1c9f354a to your computer and use it in GitHub Desktop.
Save nickymarino/e82b3efc9317c91357af351c1c9f354a to your computer and use it in GitHub Desktop.
Copy to clipboard using python
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