Last active
December 4, 2025 06:30
-
-
Save softmarshmallow/1095f9d54b84b6196a399a6a8eb0fe9f to your computer and use it in GitHub Desktop.
macOS Clipboard inspection
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.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env swift | |
| import AppKit | |
| let pb = NSPasteboard.general | |
| for (i, item) in (pb.pasteboardItems ?? []).enumerated() { | |
| print("=== Item \(i) ===") | |
| for type in item.types { | |
| print("UTI:", type.rawValue) | |
| guard let data = item.data(forType: type) else { | |
| print(" <no data>") | |
| continue | |
| } | |
| if let string = String(data: data, encoding: .utf8) { | |
| print(" UTF8 String:") | |
| print(string) | |
| } else { | |
| print(" <non-utf8 data, length \(data.count)>") | |
| } | |
| print() | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
macOS Clipboard Dumper
This script provides a reliable, developer‑friendly way to inspect the macOS clipboard as‑is, including custom formats, binary payloads, and non‑text pasteboard types.
Why this exists
macOS ships with
pbpaste, but it only exposes plain text and a few legacy formats (RTF, PostScript). When you copy data from modern apps—Grida, Sketch, Photoshop, Chrome, VSCode, or any tool that places custom UTI clipboard formats—pbpastereturns nothing.This makes debugging clipboard‑based formats extremely difficult:
This script bypasses all of those limitations by directly accessing the macOS
NSPasteboardAPI via Swift.What the script does
public.utf8-plain-text,com.figma.clipboard,public.tiff, etc.)This reveals clipboard contents exactly as the originating application placed them.
When this is useful
This script is particularly helpful when:
● Reverse‑engineering clipboard formats
Apps like Grida, Sketch, or internal tools often store rich structured data in the clipboard. This script lets you inspect the raw bytes.
● Debugging custom UTI pasteboard entries
If your app uses custom pasteboard types (e.g.,
com.myapp.node), this tool shows:● Working with binary or compressed clipboard data
Many apps compress their clipboard payloads (e.g., gzip). Inspecting and extracting the raw bytes is necessary for:
● Verifying what browsers and Electron apps put on the clipboard
Web apps may populate multiple formats:
text/html,text/plain,application/json, or vendor‑prefixed formats.● Developing OS‑level integrations or automation tools
When building automation, internal tools, or plugin systems, understanding clipboard structure is essential.
Summary
This script solves a real gap in macOS developer tooling: printing the complete clipboard, including custom types and binary formats, in a single command.
It is lightweight, requires no dependencies, and runs via:
Perfect for:
If you're working with complex clipboard formats, this gives you full visibility into the actual data stored by the system.