0

How can I make Python run a script upon the user copying something to the clipboard and then store what they copied in a variable? Should this be in some sort of a loop?

I used pyperclip for the storage of what is copied:

import pyperclip

s = pyperclip.paste()

pyperclip.copy(s)

print(s)

  • 2
    Does this answer your question? [Trigger an event when clipboard content changes](https://stackoverflow.com/questions/14685999/trigger-an-event-when-clipboard-content-changes) Or [this](https://stackoverflow.com/questions/25900770/how-to-catch-the-clipboard-event-onchangeclipboard-equivalent-from-any-applica)? What did you search so far and why did none of the solutions you found work for you? Did you even search? You've provided no information about what effort you've made, so people here are going to think you've put in no effort. – Random Davis Oct 08 '21 at 16:48
  • 1
    As @RandomDavis suggested, those links provided should give you the answer you're looking for. I just wanted to also clarify that you may have a misconception that a script you wrote can begin to run solely on a user's action. The script must already be running in an endless loop state AWAITING the user's action (in your case, read copied text); that should answer your assumption of a loop being needed. – lawgik Oct 08 '21 at 16:56

0 Answers0