You can already interact with the system clipboard in MacOS directly from the command line with two commands: pbcopy and pbpaste. I’ve made it even easier for myself by detecting whether there is data in STDINĀ — for example if we’re sending data to the command via a pipe. If so, I’ve assumed we actually want to use pbpaste. Otherwise, we want to use pbcopy.

pb () {
	if [ -t 0 ]; then
		pbpaste
	else
		pbcopy
	fi
}

You can use it like pb < /path/to/fileĀ or pb > /path/to/other/file, for example.