forked from jabbalaci/Bash-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtocb.py
More file actions
executable file
·32 lines (25 loc) · 998 Bytes
/
tocb.py
File metadata and controls
executable file
·32 lines (25 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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)