Skip to content

Syncing clipboard between two devices #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions scripts/sync_clipboard-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# sync_clipboard
This program is for syncing two computers clipboards. By this they can copy paste data from each other this works under same Wi-Fi

So to work with this you need python, beautifulsoup4,requests module to be installed.
Now after all installation,

Open the sync_clipboard_to_pc_gui.py file in that computer from which you want the copied data.
By doing this you will see a tkinter window will open with start button click on that start button.now you are ready to go.

You will see one web address in that tkinter window you have to type it manually in that computer where you want the clipboard data.

To do so, now open the sync_clipboard_from_pc_or_mobile_gui.py file on another computer in the same network.
This will open a window where you have a textbox you have to type the web address here as it is on the other computer or phone.

Use it you will automatically learned how it works.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#import asyncio
from tkinter.filedialog import askopenfile
from tkinter.filedialog import asksaveasfile
from time import sleep
import tkinter
from tkinter import filedialog
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import os,sys
#import re
from tkinter import *
import subprocess
import threading
import requests
from bs4 import BeautifulSoup as bs
import time
from bottle import route, run

#import pyperclip 'http://192.168.43.1:8080/'
def sync():

url=entry.get()
#url='http://192.168.43.147:8080/'
entry.delete(0, tkinter.END)
entry.insert(0,"connected!!! syncing to %s"%url )
while True:
#try:
global stop


c=requests.get(url)
if c.status_code==200:
print("connected!!! syncing to %s"%url,end="\r")

else:
print('tell your friend to run sync_clipboard_to_pc.py in mobile :)')
break
pr=c.text
soup=bs(pr,'html.parser')
mobile_text=soup.find('h1')
hs=mobile_text.text

pk=win.clipboard_get()
if pk not in hs:
print('i think you copied from your computer so i stop for 5 sec paste it in 2 sec')
time.sleep(5)
win.clipboard_clear()
win.clipboard_append(hs)
if stop==1:
print("i am stopped.....")
break
#except:
#print('please tell your friend to run sync_clipboard_to_pc.py in mobile :)')
#break






def stop():

# Assign global variable and set value to stop
global stop
entry.delete(0, tkinter.END)
entry.insert(0, 'i am stoped......')
stop = 1
def exiit():
win.destroy()
def start_sync(event):
global start_thread
global stop
stop=0
start_thread = threading.Thread(target=sync)
start_thread.deamon=True
start_thread.start()
win=Tk()
win.geometry("400x200")
laable=ttk.Button(win,text='start syncing',command=lambda :start_sync(None))
laable.pack()

stop = ttk.Button(win, text="Stop syncing",command=stop)
stop.pack()
entryText = tkinter.StringVar()
entry = ttk.Entry( win, textvariable=entryText,width=50 )
entry.pack()

button = ttk.Button(text = "Click and Quit", command = exiit)
button.pack()

win.mainloop()
os._exit(0)
112 changes: 112 additions & 0 deletions scripts/sync_clipboard-main/sync_clipboard_to_pc_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#import asyncio
from tkinter.filedialog import askopenfile
from tkinter.filedialog import asksaveasfile
from time import sleep
import tkinter
from tkinter import filedialog
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import os,sys
#import re
from tkinter import *
import subprocess
import threading

from bottle import route, run
import os,subprocess,re
#import pyperclip
def sync():
laable.configure(text="started")
laable.configure(command='')
d=''

if os.name =='linux':

#do
df=subprocess.getoutput('ifconfig')
ip=re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}').findall(df)
for i in ip:
if i.startswith('192'):
d+=i
break

elif os.name =='posix':

df=subprocess.getoutput('ifconfig')
ip=re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}').findall(df)
for i in ip:
if i.startswith('192'):
d+=i
break


elif os.name=='darwin':
#do

df=subprocess.getoutput('ifconfig')
ip=re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}').findall(df)
for i in ip:
if i.startswith('192'):
d+=i
break

elif os.name=='nt':
#do

df=subprocess.getoutput('ipconfig')
ip=re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}').findall(df)
for i in ip:
if i.startswith('192'):
d+=i
break


@route('/')
def hello():
#g=pyperclip.paste()
return '''<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="10">
</head>
<body>

<h1 color='blue'>%s</h1>

</body>
</html>

'''%win.clipboard_get()


#os.system('python -m http.server 8080')
entryText = tkinter.StringVar()
entry.delete(0, tkinter.END)
entry.insert(0, 'running on >> http://%s/8080/'%d)
#entryText.set('running on >> http://%s/8080/'%d)
run(host=d, port=8080, debug=True)


def start_sync(event):
global start_thread
start_thread = threading.Thread(target=sync)
start_thread.deamon=True
start_thread.start()
def exiit():
win.destroy()


win=Tk()
win.geometry("400x200")
laable=ttk.Button(win,text='start syncing',command=lambda :start_sync(None))
laable.pack()
entryText = tkinter.StringVar()
entry = ttk.Entry( win, textvariable=entryText,width=50 ,state="rw")
entry.pack()

button = ttk.Button(text = "Click and Quit", command = exiit)
button.pack()

win.mainloop()
os._exit(0)