# Osascript Clipboard

> Read and write the macOS clipboard with full type support. Use when reading clipboard text, HTML, RTF, images, or file paths (Finder copy); writing rich content; detecting clipboard changes via changeCount; or intercepting content between copy and paste.

- Skill: `damionrashford/osascript-clipboard` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx skillmds@latest add damionrashford/osascript-clipboard`
- Raw SKILL.md: https://api.skillmd.com/api/skills/damionrashford/osascript-clipboard/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: damionrashford (https://skillmd.com/u/damionrashford)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/damionrashford/osascript-clipboard

---


# 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:

```bash
uv run scripts/clipboard-read.py
```

Write plain text or text + HTML simultaneously to clipboard:

```bash
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:

```bash
uv run scripts/clipboard-watch.py
uv run scripts/clipboard-watch.py --interval 0.5
```

## Reference

- [reference/20-nspasteboard.md](reference/20-nspasteboard.md) — Full NSPasteboard API, all UTI types, change detection, multi-type write

## Key Pattern: Always clear before writing

```javascript
pb.clearContents; // always clear first
pb.setStringForType($("my text"), $("public.utf8-plain-text"));
```

Change detection without reading content:

```javascript
var before = pb.changeCount();
// ... later ...
if (pb.changeCount() !== before) {
  /* clipboard changed */
}
```

