Does the MacOS Clipboard have a path to it?

Question:

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.

Asked By: Daksh Dubey

||

Answers:

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.
Answered By: Mania