# Pbcopy

> >

- **Type:** Skill
- **Install:** `agentstack add skill-lyhcode-agent-skills-pbcopy`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [lyhcode](https://agentstack.voostack.com/s/lyhcode)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [lyhcode](https://github.com/lyhcode)
- **Source:** https://github.com/lyhcode/agent-skills/tree/main/skills/pbcopy

## Install

```sh
agentstack add skill-lyhcode-agent-skills-pbcopy
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Clipboard (pbcopy/pbpaste/osascript)

Automatically copy text, HTML, or images to the macOS clipboard so the user can paste it directly.

## When to Use

- The user explicitly asks to copy something to the clipboard
- You generate a snippet (command, code, config, URL, token) that the user said they want to paste elsewhere
- The user asks to copy an image or rich text/HTML to the clipboard
- The user asks you to "put it in my clipboard" or "copy that for me"

## Plain Text

```bash
# Copy text to clipboard
echo -n 'text to copy' | pbcopy

# Copy multi-line text to clipboard
cat TitleThis is bold' | textutil -stdin -format html -convert rtf -stdout | pbcopy

# From an HTML file
textutil -convert rtf /path/to/page.html -stdout | pbcopy

# Copy raw RTF directly (pbcopy auto-detects RTF header)
cat  /tmp/clip.html
Title
Item 1Item 2
EOF
osascript <<'APPLESCRIPT'
use framework "AppKit"
set htmlContent to do shell script "cat /tmp/clip.html"
set pb to current application's NSPasteboard's generalPasteboard()
pb's clearContents()
pb's setString:htmlContent forType:(current application's NSPasteboardTypeHTML)
APPLESCRIPT
rm /tmp/clip.html
```

## Images

`pbcopy` only handles text/RTF/EPS — images require `osascript` with NSPasteboard.

```bash
# Copy image to clipboard (PNG, JPG, GIF, TIFF, BMP, WebP)
osascript <<APPLESCRIPT
use framework "AppKit"
set img to (current application's NSImage's alloc()'s initWithContentsOfFile:"/path/to/image.png")
set pb to current application's NSPasteboard's generalPasteboard()
pb's clearContents()
pb's writeObjects:{img}
APPLESCRIPT
```

## Reading Clipboard

```bash
# Read plain text
pbpaste

# Read as RTF
pbpaste -Prefer rtf

# Check clipboard content types
osascript -e 'the clipboard as record'

# Save clipboard image to file
osascript <<'APPLESCRIPT'
use framework "AppKit"
set pb to current application's NSPasteboard's generalPasteboard()
set imgData to pb's dataForType:(current application's NSPasteboardTypePNG)
if imgData is not missing value then
  imgData's writeToFile:"/tmp/clipboard.png" atomically:true
  return "Saved to /tmp/clipboard.png"
else
  return "No image on clipboard"
end if
APPLESCRIPT
```

## Rules

1. **Use `echo -n`** (no trailing newline) for single-line values like URLs, tokens, and one-liners.
2. **Use heredoc with `'EOF'`** (single-quoted delimiter) for multi-line content to prevent shell expansion.
3. **Always confirm** what was copied by telling the user — e.g., "Copied the API key to your clipboard."
4. **Never silently copy** — always inform the user when you put something in their clipboard.
5. **Sensitive data** — warn the user if clipboard content contains secrets, as clipboard contents can be read by other apps.
6. **Temp files** — delete any temp files (`/tmp/clip.html`, etc.) after copying to clipboard.
7. **Choose the right method:**
   - Plain text → `echo | pbcopy`
   - HTML/rich text → `textutil -convert rtf -stdout | pbcopy` (preferred) or `osascript` for native HTML type
   - Images → `osascript` with `NSImage` + `NSPasteboard` (pbcopy cannot handle images)
8. **macOS only** — these commands use macOS APIs. On Linux, suggest `xclip -selection clipboard` or `xsel --clipboard` for text (rich content requires `xclip -t text/html` or similar).

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [lyhcode](https://github.com/lyhcode)
- **Source:** [lyhcode/agent-skills](https://github.com/lyhcode/agent-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-lyhcode-agent-skills-pbcopy
- Seller: https://agentstack.voostack.com/s/lyhcode
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
