Clipboardbuffers.py: Difference between revisions
From Lucca's Wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
import sys | import sys | ||
import os | |||
import time | import time | ||
import pyperclip | import pyperclip | ||
Line 19: | Line 20: | ||
clipboardBuffer = [] | clipboardBuffer = [] | ||
clipboardBuffer = ["No value in this clipboard buffer" for i in range(10)] | clipboardBuffer = ["No value in this clipboard buffer" for i in range(10)] | ||
#check if pickle file exists, if not, then create one | |||
if os.path.isfile("clipboardBufferData.pk"): | |||
getClipboardBufferFromFile() | |||
else: | |||
dumpClipboardBufferToFile() | |||
def inputbox(inputBuffer): | def inputbox(inputBuffer): |
Revision as of 00:22, 12 December 2024
import sys import os import time import pyperclip import pyautogui import pickle from tkinter import *
def dumpClipboardBufferToFile():
global clipboardBuffer with open("clipboardBufferData.pk", 'wb') as fi: pickle.dump(clipboardBuffer, fi)
def getClipboardBufferFromFile():
global clipboardBuffer with open("clipboardBufferData.pk", 'rb') as fi: clipboardBuffer = pickle.load(fi)
- scriptFolder = (os.path.dirname(__file__))
clipboardBuffer = [] clipboardBuffer = ["No value in this clipboard buffer" for i in range(10)]
- check if pickle file exists, if not, then create one
if os.path.isfile("clipboardBufferData.pk"):
getClipboardBufferFromFile()
else:
dumpClipboardBufferToFile()
def inputbox(inputBuffer):
inputText = "No Input Given Yet" master = Tk() textbox = Entry(master) textbox.pack() textbox.insert(0, clipboardBuffer[inputBuffer]) textbox.focus_set() def onclick(pos): nonlocal inputText inputText = textbox.get() global clipboardBuffer clipboardBuffer[inputBuffer] = inputText print(f"Clipboard buffer {inputBuffer} was set to: {inputText}") master.destroy() b = Button(master, text="OK", width=10, command=onclick) b.pack() textbox.bind('<Return>', onclick) mainloop() print(clipboardBuffer) dumpClipboardBufferToFile() return (inputText)
def typeBuffer(inputBuffer):
global clipboardBuffer pyautogui.write(clipboardBuffer[inputBuffer])
def copyToBuffer(inputBuffer):
global clipboardBuffer pyautogui.hotkey('ctrl', 'c') time.sleep(1) clipboardBuffer[inputBuffer] = pyperclip.paste() dumpClipboardBufferToFile()
if sys.argv[1] == "paste":
typeBuffer(int(sys.argv[2]))
if sys.argv[1] == "copy":
copyToBuffer(int(sys.argv[2]))
if sys.argv[1] == "edit":
inputbox(int(sys.argv[2]))