I am trying to write a small clipboard logger (for linux) that listens for an event (changing the contents of the clipboard) and writes the contents of the clipboard to a file (on-change).
What I came up with is a simple while loop with the pyperclip clipper module:
import pyperclip
recent_value = ""
while True:
tmp_value = pyperclip.paste()
if tmp_value != recent_value:
recent_value = tmp_value
with open(".clipboard_history.txt", "a") as f:
f.write(recent_value + "\n")
So, my first question is: can I actually run a True loop to “listen”, or will it be too much memory or generally ineffective or bad practice?
And the second question: how can I run this in the background, like shell job management (ampersand)?
Should I go for a demon, such as the one offered here, or some kind of event loop or flow magic?
-, ( ), ( ) .
============================
edit: ! + : , ?