0

I am currently working on a python program that makes use of the clipboard. If you want to know more, I am finding a way to access clipboard history, which is very hard to find for free. I then realized I had no idea how to access the clipboard. My main question is, is there a way to access the clipboard and read what it says through python with any module? Or, does the MacOS Clipboard have a path that I can use to read the file and get the clipboard?

I only used two modules, pyperclip and clipboard. These two apparently only have the copy & paste function.

Mania
  • 98
  • 7
  • I found this post enlightening on the topic of interacting with clipboards programmatically: https://stackoverflow.com/questions/749544/pipe-to-from-the-clipboard-in-a-bash-script – Mike L Nov 26 '22 at 09:00
  • 1
    There is no file, and thus no path. The clipboard only exists in memory. – tripleee Nov 26 '22 at 09:02

1 Answers1

2

In macOS, once you copy something else, the previous item disappears. macOS clipboard is designed to hold one item at a time.

To get the last clipboard item in python use this:

import pyperclip as pc

clipboard = pc.paste()
print(clipboard)

A solution to your query:

  1. Run a code that checks the pc.paste() value periodically(e.g. every second) for any change and adds the new value to a variable/file that preserves a history of the records.
  2. Same as number 1 but instead of adopting a periodical approach, watches pc.paste() for any change using python pdb library. It's for debugging but you can trace any change in the value of a variable using pdb.set_trace() function.
Mania
  • 98
  • 7