Last active
April 29, 2023 05:46
-
-
Save MohitDabas/bc12635b65c5d128344895ba08dd879e to your computer and use it in GitHub Desktop.
Python based mac clipboard saver using Kivy Gui (Macos only).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#please install kivy by using command !pip install kivy | |
import subprocess | |
from kivy.app import App | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.uix.textinput import TextInput | |
from kivy.core.clipboard import Clipboard | |
from kivy.clock import Clock | |
class MyBoxLayout(BoxLayout): | |
def __init__(self, **kwargs): | |
super(MyBoxLayout, self).__init__(**kwargs) | |
# create text input widget and add to widget | |
self.text_input = TextInput(text='', font_size=20, readonly=True) | |
self.add_widget(self.text_input) | |
# start clipboard checking | |
Clock.schedule_interval(self.check_clipboard, 1) | |
def check_clipboard(self, dt): | |
# get input from clipboard | |
pbpaste_output = Clipboard.paste() | |
if pbpaste_output != self.text_input.text: | |
# add new inputs to text input | |
new_inputs = pbpaste_output.split('\n') | |
for i in range(len(new_inputs)): | |
if new_inputs[i]: | |
self.text_input.text += f"{len(self.text_input.text.splitlines())+1}. {new_inputs[i]}\n" | |
# copy all inputs to clipboard | |
Clipboard.copy(self.text_input.text) | |
class MyApp(App): | |
def build(self): | |
return MyBoxLayout() | |
if __name__ == '__main__': | |
MyApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment