osascript-clipboard
NSPasteboard via JXA — handles all clipboard types simultaneously.
theClipboard() in JXA standard additions is plain text only. NSPasteboard is the full API.
Clipboard Types
| UTI | Content |
|---|---|
public.utf8-plain-text |
Plain text |
public.html |
HTML with styling (web copy) |
public.rtf |
Rich Text Format |
public.tiff / public.png |
Image data |
NSFilenamesPboardType |
File paths (Finder copy) |
public.url |
URL string |
Scripts
Read all clipboard types — text, HTML, file paths, image presence:
uv run scripts/clipboard-read.py
Write plain text or text + HTML simultaneously to clipboard:
uv run scripts/clipboard-write.py "plain text content"
uv run scripts/clipboard-write.py "plain text" --html "<b>plain text</b>"
Poll changeCount and print new clipboard content whenever it changes:
uv run scripts/clipboard-watch.py
uv run scripts/clipboard-watch.py --interval 0.5
Reference
- reference/20-nspasteboard.md — Full NSPasteboard API, all UTI types, change detection, multi-type write
Key Pattern: Always clear before writing
pb.clearContents; // always clear first
pb.setStringForType($("my text"), $("public.utf8-plain-text"));
Change detection without reading content:
var before = pb.changeCount();
// ... later ...
if (pb.changeCount() !== before) {
/* clipboard changed */
}