I want to run a simple python script in the background that reads text from the clipboard and prints it out. Here is my code.
#!/usr/bin/env python import Tkinter last_clipboard = "" def get_clipboard(): global last_clipboard root = Tkinter.Tk() root.withdraw() # Hide the main window (optional) text_in_clipboard = root.clipboard_get() if text_in_clipboard != last_clipboard: last_clipboard = text_in_clipboard print last_clipboard while True: get_clipboard()
This is working as expected but it consumes too much CPU (100% CPU).
How can I make it work correctly without consuming that much?