Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4d1f1a1c3f
Fetching contributors…

Cannot retrieve contributors at this time

executable file 33 lines (25 sloc) 0.998 kb
#!/usr/bin/env python
# Website: https://pythonadventures.wordpress.com/2011/03/05/copy-string-to-x-clipboards/
# Laszlo Szathmary, 2011--2012 (jabba.laci@gmail.com)
#
# Copy the text from the standard input to ALL clipboards. Thus, you can use
# any paste method to insert your text (middle mouse button or Shift+Insert).
# tocb.py -> "to clipboard(s)"
#
# Requirement: xsel package (sudo apt-get install xsel).
#
# Usage: cat file.txt | tocb
import sys
import subprocess
#############################################################################
def text_to_clipboards(text):
# "primary":
xsel_proc = subprocess.Popen(['xsel', '-pi'], stdin=subprocess.PIPE)
xsel_proc.communicate(text)
# "clipboard":
xsel_proc = subprocess.Popen(['xsel', '-bi'], stdin=subprocess.PIPE)
xsel_proc.communicate(text)
#############################################################################
if __name__ == "__main__":
stuff = sys.stdin.read()
text_to_clipboards(stuff)
Jump to Line
Something went wrong with that request. Please try again.