Clean invisible characters and awkward whitespace from copied text without
sending it anywhere. pbclean is a small command-line tool for prose copied
from PDFs, websites, chat apps, and documents. On macOS, it can clean the
clipboard in place with one command.
$ printf 'Hello\u00a0world\u200b! \r\n' | pbclean
Hello world!The input above contains a non-breaking space, a zero-width space, trailing spaces, and a Windows line ending. The output does not.
- Private: processing stays on your computer.
- Small: the runtime uses only Python's standard library.
- Predictable: paragraph breaks and visible wording stay intact.
- Scriptable: read from the clipboard, a UTF-8 file, or standard input.
- Native on macOS: clipboard support uses the built-in
pbpasteandpbcopycommands.
Install the latest version directly from GitHub:
python3 -m pip install \
"git+https://github.com/ydsveluvolu2996/mac-clipboard-cleaner.git"Then clean your macOS clipboard in place:
pbclean --clipboard --copyFor an isolated command-line installation, use
pipx:
pipx install git+https://github.com/ydsveluvolu2996/mac-clipboard-cleaner.git| Input problem | Result |
|---|---|
| Zero-width spaces, joiners, word joiners, byte-order marks | Removed |
| Non-breaking and narrow non-breaking spaces | Converted to regular spaces |
Windows (CRLF) and classic Mac (CR) line endings |
Normalized to LF |
| Spaces and tabs at the ends of lines | Removed by default |
pbclean is intended for copied prose and source text. Zero-width joiners can
be meaningful in some languages and emoji sequences, so inspect the result
before using it with text where those characters are intentional.
Pipe copied or generated text through pbclean:
some-command | pbcleanClean a UTF-8 text file:
pbclean notes.txt > notes-clean.txtKeep spaces and tabs at the ends of lines:
pbclean --keep-trailing-whitespace notes.txtThe package can also run as a Python module:
python3 -m pbclean --versionPrint cleaned clipboard text without changing the clipboard:
pbclean --clipboardClean the clipboard and immediately copy the result back:
pbclean --clipboard --copyYou can also send file or standard-input content to the clipboard with
--copy. Clipboard options require macOS; file and standard-input cleaning work
wherever Python does.
The cleaning function is available for scripts and applications:
from pbclean import clean_text
cleaned = clean_text("Copied\u00a0text\u200b")
assert cleaned == "Copied text"Clone the project, install it, and run its standard-library test suite:
git clone https://github.com/ydsveluvolu2996/mac-clipboard-cleaner.git
cd mac-clipboard-cleaner
python3 -m pip install .
python3 -m unittest discover -s tests -vPull requests are welcome. See CONTRIBUTING.md for the small project checklist.