Way to see the invisible formatting in the clipboard and/or create the formatting when piping to pbcopy

copy/pasteformattingscriptterminal

Is there a way to see the contents of my clipboard in a way that shows me what formatting metadata is included?

Or to get to the question behind the question: is there a way to generate output in a script so that if I pipe the output to pbcopy it will include the formatting?

Specific example: if I write a script that generates a newline-delimited list of names, and then paste it into a table in Confluence, it will just dump the results into a single cell. I'd like to be able to paste it so that the whole column is filled up (with one name per cell).

I can do this by pasting the results into a Google Spreadsheet and then re-copying the column from Google Spreadsheet. For some reason that adds invisible formatting that allows me to paste the cells into Confluence, but when I inspect the clipboard (in Finder's Edit->Show Clipboard, or using pbpaste | hexdump) it seems exactly the same as the output of my script. I've often had this problem with formatting text for the clipboard, and I'd really like to know what tricks there are for viewing and generating this magical invisible formatting.

Best Answer

An thing on the clipboard is actually an OO-style object which has methods to render itself appropriately in each context. So the reason that your hex dump from PBCOPY is the same even when the object on the clipboard is different is because the text-only renderings are both the same.

Just as a file on the clip board will render as its ascii file path in contexts that only accept text pastes. I believe that pbcopy and pbpaste only operate with this textual format for the objects on the clipboard, so you cannot use them to do what you are aiming to do.

If I understand your objective correctly, you could hack it, by using an application like textedit, and feed the application as an rtf (rich text formatted file) then send a COMMAND-A, then COMMAND-C to the text edit application (or perhaps a text-edit specific dictionary commands).

This is really hacky, and it would result in visible action on your screen, but it would be a scripted way to get ascii encoded markup onto the clipboard.

Post a follow up, if you want help implementing this.