pbpaste - macOS


Overview

pbpaste is a command-line utility for retrieving the contents of the macOS pasteboard. It provides a simple interface for accessing and manipulating text, images, and other data stored in the pasteboard.

Syntax

pbpaste [options]

Options/Flags

-e | –escape-backslashes | Escapes backslashes () in the pasteboard contents.

-p | –plain-text | Outputs the contents of the pasteboard as plain text, removing any formatting or rich text elements.

-L | –line | Outputs the pasteboard contents as a single line of text.

-T | –type-only | Outputs only the type of data stored in the pasteboard.

-d | –debug | Prints debugging information about the pasteboard.

Examples

Get the contents of the pasteboard:

pbpaste

Get the contents of the pasteboard as plain text:

pbpaste -p

Output the type of data stored in the pasteboard:

pbpaste -T

Escape backslashes in the pasteboard contents:

pbpaste -e

Retrieve the contents of the pasteboard as a single line of text:

pbpaste -L

Common Issues

  • pbpaste may fail if the pasteboard contains data that cannot be converted to text, such as images or files.
  • If pbpaste outputs unexpected results, try using the -e flag to escape backslashes or the -p flag to output plain text.

Integration

pbpaste can be combined with other macOS commands to perform more advanced tasks. For example:

Copy the contents of a file to the pasteboard and then paste it into a document:

cat myfile.txt | pbpaste | nano -

Convert the contents of the pasteboard to uppercase using the tr command:

pbpaste | tr '[:lower:]' '[:upper:]'
  • pbcopy: Copies the specified text or file to the pasteboard.
  • pbcopy: Copies the specified text or file to the pasteboard.
  • xclip: A cross-platform command-line clipboard manager.
  • Pasteboard API Reference: Apple’s official documentation for the pasteboard.