forked from WillBux/Custom-Clipboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClipboard.py
139 lines (98 loc) · 2.51 KB
/
Clipboard.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
__Author__ = "Will Buxton"
__editor__ = "Nicholas Beninato"
import subprocess
import os
try:
from pynput import keyboard
from pynput.keyboard import Key
except ImportError:
while True:
print("The package pynput is not installed. Want to install it? ", end='')
choice = input().lower()
if choice[0] == 'y':
os.system("python3 -m pip install pynput")
exit()
elif choice[0] == 'n':
print('Goodbye!')
exit()
else:
print("Please respond with [y/n]")
copy = """osascript -e 'tell application "System Events" to keystroke "c" using {command down}'"""
paste = """osascript -e 'tell application "System Events" to keystroke "v" using {command down}'"""
buckets = {1: "", 2: "", 3: "", 4: "", 5: "", 6: ""}
def f1():
os.system(copy)
buckets[1] = getClipboardData()
def f2():
setClipboardData(buckets[1])
os.system(paste)
def f3():
os.system(copy)
buckets[2] = getClipboardData()
def f4():
setClipboardData(buckets[2])
os.system(paste)
def f5():
os.system(copy)
buckets[3] = getClipboardData()
def f6():
setClipboardData(buckets[3])
os.system(paste)
def f7():
os.system(copy)
buckets[4] = getClipboardData()
def f8():
setClipboardData(buckets[4])
os.system(paste)
def f9():
os.system(copy)
buckets[5] = getClipboardData()
def f10():
setClipboardData(buckets[5])
os.system(paste)
def f11():
os.system(copy)
buckets[6] = getClipboardData()
def f12():
setClipboardData(buckets[6])
os.system(paste)
def on_press(key):
if key == Key.f1:
f1()
elif key == Key.f2:
f2()
elif key == Key.f3:
f3()
elif key == Key.f4:
f4()
elif key == Key.f5:
f5()
elif key == Key.f6:
f6()
elif key == Key.f7:
f7()
elif key == Key.f8:
f8()
elif key == Key.f9:
f9()
elif key == Key.f10:
f10()
elif key == Key.f11:
f11()
elif key == Key.f12:
f12()
def on_release(key):
return key
def getClipboardData():
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE)
retcode = p.wait()
data = p.stdout.read()
return data
def setClipboardData(data):
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
p.stdin.write(data)
p.stdin.close()
retcode = p.wait()
# Collect events until released
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()