PyObjC is the way to go:

#!/usr/bin/python

from AppKit import NSPasteboard, NSStringPboardType

pb = NSPasteboard.generalPasteboard()
pbstring = pb.stringForType_(NSStringPboardType)
print u"Pastboard string: %s".encode("utf-8") % repr(pbstring)

This only supports text and will return None otherwise. You can extend it to support other data types as well, see NSPastboard Class Reference.

Answer from MagerValp on Stack Overflow
🌐
PyPI
pypi.org › project › pasteboard
pasteboard
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
PyPI
pypi.org › project › clipboard
clipboard · PyPI
Works for Windows, Mac and Linux. Well, as I was trying to implement this, I realize that everything is included in pyperclip already: https://pypi.python.org/pypi/pyperclip/ But anyway, clipboard is a better name. You are free to choose:-) I might add more features to it. ... import clipboard clipboard.copy("abc") # now the clipboard content will be string "abc" text = clipboard.paste() # text will have the content of clipboard ... Download the file for your platform.
      » pip install clipboard
    
Published   May 22, 2014
Version   0.0.4
🌐
Macdrifter
macdrifter.com › 2011 › 12 › python-and-the-mac-clipboard.html
Python and the Mac Clipboard - Macdrifter
December 2, 2011 - After some reading and fiddling[1], I ended up with a version of the above script that uses the NSPasteboard class to get and set the clipboard instead of a using the shell command. :::Python import urllib2 from Foundation import * from AppKit import # Sets the clipboard to a string def pbcopy(s): pb = NSPasteboard.generalPasteboard() pb.declareTypes_owner_([NSStringPboardType], None) newStr = NSString.stringWithString_(s) newData = newStr.nsstring().dataUsingEncoding_(NSUTF8StringEncoding) pb.setData_forType_(newData, NSStringPboardType) # Gets the clipboard contents def pbpaste(): pb = NSPasteboard.generalPasteboard() content = pb.stringForType_(NSStringPboardType) return content f = urllib2.urlopen(pbpaste()) source = f.read() f.close() newurl = f.geturl() newurl = newurl.split('?')[0] pbcopy(newurl)
🌐
PyPI
pypi.org › project › pyperclip
pyperclip · PyPI
Otherwise run "sudo apt-get install xclip" or "sudo apt-get install xsel" (Note: xsel does not always seem to work.) Otherwise on Linux, you will need the qtpy or PyQT5 modules installed.
      » pip install pyperclip
    
Published   Sep 26, 2025
Version   1.11.0
🌐
GitHub
gist.github.com › luqmaan › d8bc61e746207bb12f11
Write a python string to the clipboard via pbcopy (OS X) · GitHub
Download ZIP · Write a python string to the clipboard via pbcopy (OS X) Raw · write_to_clipboard.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
GitHub
github.com › terryyin › clipboard
GitHub - terryyin/clipboard: A cross platform clipboard operation library of Python. Works for Windows, Mac and Linux.
A cross platform clipboard operation library of Python. Works for Windows, Mac and Linux. - terryyin/clipboard
Starred by 89 users
Forked by 6 users
Languages   Python 86.7% | Makefile 13.3% | Python 86.7% | Makefile 13.3%
🌐
GitHub
github.com › asweigart › pyperclip
GitHub - asweigart/pyperclip: Python module for cross-platform clipboard functions. · GitHub
Pyperclip is a cross-platform Python module for copy and paste clipboard functions. It works with Python 2 and 3. Install on Windows: pip install pyperclip · Install on Linux/macOS: pip3 install pyperclip · Al Sweigart al@inventwithpython.com BSD License ·
Starred by 1.8K users
Forked by 222 users
Languages   Python
🌐
Readthedocs
pyperclip.readthedocs.io › en › latest
Welcome to Pyperclip’s documentation! — Pyperclip 1.5 documentation
Pyperclip provides a cross-platform Python module for copying and pasting text to the clipboard.
🌐
ActiveState
code.activestate.com › recipes › 410615-manipulate-mac-os-clipboard
Manipulate Mac OS clipboard « Python recipes « ActiveState Code
April 20, 2005 - This will no longer work in current MacOSX versions, as born out by the documentation: https://docs.python.org/2/library/carbon.html#module-Carbon.Scrap
🌐
GeeksforGeeks
geeksforgeeks.org › installation guide › how-to-install-pyperclip-in-python-on-macos
How to Install pyperclip in Python on MacOS? - GeeksforGeeks
July 23, 2025 - ... Step 3: Upgrade your pip to avoid errors during installation. ... Step 4: Enter the following command to install pyperclip using pip3. ... Step 1: Download the latest source package of pyperclip for python3 from here.
🌐
The Building Coder
thebuildingcoder.typepad.com › blog › 2013 › 06 › python-mac-pasteboard-access.html
Python Mac Pasteboard Access - The Building Coder - TypePad
June 2, 2013 - Thanks to the platform independence provided by Python, the only thing that needs changing is to replace the Windows clipboard access by Mac pasteboard read and write operations.
🌐
PyPI
pypi.org › project › pyperclip3
pyperclip3 · PyPI
February 1, 2021 - Cross-platform clipboard utilities supporting both binary and text data.
      » pip install pyperclip3
    
Published   Feb 01, 2021
Version   0.4.1
🌐
Python.org
discuss.python.org › python help
Copy to system clipboard - Python Help - Discussions on Python.org
June 2, 2022 - I’m working on a an app (my 2nd GUI app) that generates a hash value (AKA: checksum) based on a selected file. Right now, the hash value is displayed in a Text Widget, which is has the ‘state’ set to ‘disabled’, so that …
🌐
iZZiSwift
izziswift.com › home › privacy policy › python get mac clipboard contents
Python get mac clipboard contents - iZZiSwift
December 11, 2020 - from pandas.io.clipboard import clipboard_get text = clipboard_get() You can grab the clipboard (and the screen) with PIL/Pillow on a Mac like this: