-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosclip.py
73 lines (59 loc) · 1.78 KB
/
osclip.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
"""
OsClip: bi-directional clipboard sharing between computers (PC or Mac)
based on pyperclip and python-osc
by: zappfinger (Richard van Bemmelen)
version: 1.0
date: 13-10-2018
"""
from pythonosc import dispatcher
from pythonosc import osc_server, udp_client
import time
import threading
import pyperclip
"""
enter the ip address of PC or Mac to share the clipboard with
enter this machine's ip address on the other machine as well
"""
##########################
otherIP = '192.168.1.9'
##########################
magic = 'm@gic:'
class server():
def __init__(self, ip, port):
self.dispatcher = dispatcher.Dispatcher()
self.dispatcher.map("/clip", self.print_clip_handler, "")
self.server = osc_server.ThreadingOSCUDPServer((ip, port), self.dispatcher)
def print_clip_handler(self, unused_addr, args, cliptext):
print("{0}".format(cliptext))
if magic in cliptext:
cliptext = cliptext[6:]
pyperclip.copy(cliptext)
class client():
def __init__(self, ip, port):
self.oldclip = ''
self.client = udp_client.SimpleUDPClient(ip, port)
def send(self): # send when clipboard has changed
while 1:
pasted = pyperclip.paste()
if not (magic in pasted) and pasted!= self.oldclip:
self.client.send_message("/clip", magic + pasted)
self.oldclip = pasted
print(self.oldclip)
time.sleep(1)
if __name__ == "__main__":
def worker1():
serv = server('0.0.0.0', 8888)
print("Serving on {}".format(serv.server.server_address))
serv.server.serve_forever()
def worker2():
clint = client(otherIP, 8888)
clint.send()
thread_list = []
thread1 = threading.Thread(target=worker1)
thread_list.append(thread1)
thread1.start()
thread2 = threading.Thread(target=worker2)
thread_list.append(thread2)
thread2.start()
while 1:
time.sleep(.5) # uses less CPU than pass