From 78be41305c958661f65253dad0ad18fe73d697c0 Mon Sep 17 00:00:00 2001 From: Yogesh Vishwakarma <103316955+Yogeshkarma@users.noreply.github.com> Date: Mon, 6 Oct 2025 12:50:23 +0530 Subject: [PATCH 1/2] Implement clipboard manager with GUI and history logging This script monitors the clipboard for changes and saves the clipboard history to a file. It also provides a GUI to display the history and clear it when needed. --- Clipboard Manager/main.py | 103 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Clipboard Manager/main.py diff --git a/Clipboard Manager/main.py b/Clipboard Manager/main.py new file mode 100644 index 0000000..430eb66 --- /dev/null +++ b/Clipboard Manager/main.py @@ -0,0 +1,103 @@ +import pyperclip +import tkinter as tk +from tkinter import scrolledtext +import time +import threading +import os +import queue + +history_file = os.path.join(os.path.expanduser("~"), "clipboard_history.txt") + +if not os.path.exists(history_file): + with open(history_file, "w", encoding="utf-8") as f: + f.write("Clipboard History:\n\n") + +last_text = "" + +gui_queue = queue.Queue() + +MAX_HISTORY_LINES = 1000 + + +def monitor_clipboard(): + global last_text + while True: + try: + text = pyperclip.paste() + except Exception: + time.sleep(1) + continue + if text != last_text and text.strip() != "": + last_text = text + timestamped_text = f"{time.strftime('%Y-%m-%d %H:%M:%S')} - {text}\n" + try: + with open(history_file, "a", encoding="utf-8") as f: + f.write(timestamped_text) + except Exception: + pass + gui_queue.put(timestamped_text) + time.sleep(1) + +def limit_file_size(): + try: + with open(history_file, "r", encoding="utf-8") as f: + lines = f.readlines() + + header = lines[:2] + history = lines[2:] + if MAX_HISTORY_LINES is not None and len(history) > MAX_HISTORY_LINES: + history = history[-MAX_HISTORY_LINES:] + with open(history_file, "w", encoding="utf-8") as f: + f.writelines(header + history) + except Exception: + pass + + +def process_queue(): + while not gui_queue.empty(): + text = gui_queue.get() + text_area.configure(state='normal') + text_area.insert(tk.END, text) + text_area.configure(state='disabled') + text_area.yview(tk.END) + root.after(100, process_queue) + +# +def clear_history(): + text_area.configure(state='normal') + text_area.delete(1.0, tk.END) + text_area.configure(state='disabled') + try: + with open(history_file, "w", encoding="utf-8") as f: + f.write("Clipboard History:\n\n") + except Exception: + pass + +root = tk.Tk() +root.title("Clipboard Manager") +root.geometry("600x400") + +text_area = scrolledtext.ScrolledText(root, wrap=tk.WORD, state='disabled') +text_area.pack(expand=True, fill='both', padx=10, pady=10) + +clear_button = tk.Button(root, text="Clear History", command=clear_history) +clear_button.pack(pady=5) + + +limit_file_size() +try: + with open(history_file, "r", encoding="utf-8") as f: + text_area.configure(state='normal') + text_area.insert(tk.END, f.read()) + text_area.configure(state='disabled') +except Exception: + pass + + +thread = threading.Thread(target=monitor_clipboard, daemon=True) +thread.start() + + +root.after(100, process_queue) + +root.mainloop() From 464197a9200ae42d2c401289f80773b5c7053ca3 Mon Sep 17 00:00:00 2001 From: Yogesh Vishwakarma <103316955+Yogeshkarma@users.noreply.github.com> Date: Mon, 6 Oct 2025 12:55:40 +0530 Subject: [PATCH 2/2] Add README for Clipboard Manager Scripts --- Clipboard Manager/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Clipboard Manager/README.md diff --git a/Clipboard Manager/README.md b/Clipboard Manager/README.md new file mode 100644 index 0000000..c31ce7b --- /dev/null +++ b/Clipboard Manager/README.md @@ -0,0 +1,25 @@ + +# 📋 Clipboard Manager + +**Clipboard Manager** is a Python desktop application that automatically monitors and saves your clipboard history. With a simple GUI, you can view, manage, and clear all the text you've copied, ensuring that nothing important is lost. + +--- + +## **Requirements** +- Python 3.x +- `pyperclip` library +```bash +pip install pyperclip +```` + +--- + +## **Benefits** + +* 🖱 **Real-time monitoring**: Automatically tracks copied text. +* 📝 **Persistent history**: Saves all clipboard entries to a text file in your home directory. +* 📜 **Scrollable GUI**: Easily browse your clipboard history. +* 🗑 **Clear history**: Delete all stored entries from both the GUI and the file. +* 🔄 **Thread-safe updates**: Updates the GUI without freezing the application. + +