6

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.

5

2 Answers 2

3

For a GUI option:

Download Additional tools for Xcode from https://developer.apple.com/download/all/?q=xcode

Open Clipboard Viewer. It doesn't seem to have a CLI interface though.

From Finder, you can also inspect the clip board from the edit menu

  • Show Clipboard

There’s also a tool pbv which handles rich text better than the pbpaste command does.

5
  • The Finder has a built-in window to display the Clipboard's content.
    – benwiggy
    Mar 3, 2022 at 14:20
  • @benwiggy Does it?
    – nohillside
    Mar 3, 2022 at 14:40
  • 3
    @nohillside Yes, Edit > Show Clipboard. If the text is formatted, it will show the formatting.
    – benwiggy
    Mar 3, 2022 at 16:45
  • 2
    @benwiggy I‘m using OS X/macOS for nearly 20 years now, never noticed that. Thanks :-)
    – nohillside
    Mar 3, 2022 at 17:01
  • @nohillside It's been there since Classic Mac days!
    – benwiggy
    Mar 3, 2022 at 19:02
6

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .