pbs - macOS
pbs: A Command-Line Tool for Setting and Getting Clipboard Contents on macOS
Overview
pbs is a command-line utility that allows you to interact with the macOS clipboard, enabling you to set, get, and manipulate its contents. It provides a powerful way to automate clipboard-related tasks and integrate them into your workflows.
Syntax
pbs [options] [text]
Options/Flags
- -c, –copy: Copy the specified text to the clipboard.
- -d, –delete: Clear the clipboard.
- -g, –get: Output the current clipboard contents.
- -h, –help: Display help information.
- -v, –version: Display the program version.
- -i, –stdin: Read text from standard input and copy it to the clipboard.
- -o, –stdout: Output the clipboard contents to standard output.
Examples
Set Clipboard Contents:
pbs -c "Hello, world!"
Get Clipboard Contents:
pbs -g
Clear Clipboard:
pbs -d
Set Clipboard Contents from File:
cat sample.txt | pbs -i
Output Clipboard Contents to File:
pbs -g > output.txt
Common Issues
- “Operation not permitted” error: Ensure you have granted pbs access to the Accessibility API in System Preferences > Security & Privacy > Privacy > Accessibility.
- Clipboard not updating: Quit and relaunch pbs or the application that uses the clipboard.
Integration
- Use pbs with other command-line tools for task automation, e.g., using pbpaste | pbs -i to copy the output of another command to the clipboard.
- Integrate pbs into scripts and workflows to streamline clipboard-related operations, e.g., automatically pasting specific text upon login.
Related Commands
- pbcopy: Copy text to the clipboard without displaying it.
- pbpaste: Output the clipboard contents to standard output.
- xclip: An alternative command-line tool for clipboard manipulation.