Clipboards

Continuing the discussion from Copytables Simplifies Extracting Tabular Data from Web Pages:

I wonder which “old one” you’re thinking of.

As far as I remember, the Mac clipboard (and Windows’ as well) has always been this big multi-format API. An app that copies data to the clipboard can copy it in as many formats as it wants. This is why you could (for example) copy formatted text in MacWrite, paste it with formatting into another word processor, or paste it as plain text into a text editor.

An app can also just declare itself the owner of the clipboard without moving any data - and later handle callbacks from the OS when other apps try to access it.

This latter approach is what is typically done for non-trivial apps. Your app isn’t going to copy a dozen different representations of the copied text, because that’s a waste of CPU time and memory. So it will take ownership and when asked, it will present the list of every format it can generate. And when an app tries to get the actual data (e.g. as a part of a paste), it will generate the data on the fly and return it.

Which is why, when quitting an app like Word, you’ll often see a message like “there’s a lot of data on the clipboard, do you want to preserve it?”. Because the app didn’t actually put the data there, so after it quits, the clipped data will be lost (the clipboard will have no owner). If you answer yes, it will then generate all the supported representations and copy them all to the clipboard, so it can be pasted after the app quits.

1 Like

Tee hee! Well, I was using a bit of poetic license. Nevertheless I remember there being only a couple back in the early nineties.

Now? I just copied an image from Safari (that was a link, too) from the NYT front page and this is what’s on “the” clipboard:

public.tiff
NeXT TIFF v4.0 pasteboard type
dyn.ah62d4rv4gu8zs3pcnzme2641f4guzdmsv0gn64uqm10c6xenv61a3k
WebURLsWithTitlesPboardType
dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw055bsmwca7d3sbwu
Apple URL pasteboard type
public.url
'url ’ (CorePasteboardFlavorType 0×75726C20)
public.url-name
‘urin’ (CorePasteboardFlavorType 0×75726C6E)
public.utf8-plain-text
NSStringPboardType
com.apple.flat-rtfd
NeXT RTFD pasteboard type
com.apple.webarchive
Apple Web Archive pasteboard type
public.html
Apple HTML pasteboard type

Yes, all of that is referring to that one image.

And, here, for your delectation is what’s on the clipboard after copying three cells from a Numbers spreadsheet:

com.apple.iWork.TSPNativeData
com.apple.iWork.TSPNativeMetadata
com.apple.iWork.TSPDescription
com.apple.iWork.pasteboardState.largestRowsAndColumnsInTables-1-3
com.apple.iWork.pasteboardState.maxinlinenestingdepth-1
com.apple.iWork.pasteboardState.numberOfDrawables-1
com.apple.iWork.pasteboardState.singleTableld-68B384C7-9E7F-4B90-A1F5-067B81524A6A
com.apple.iWork.pasteboardState.hasNativeDrawables
com.apple.iWork.pasteboardState.numberOfTopLevelDrawables-1
com.apple.iWork.pasteboardState.elementKinds-4
com.apple.iWork.pasteboardState.hasNativeTypes
com.apple.iWork.pasteboardState.singleTableDrawable
com.apple.iWork.pasteboardState.hasTablesWithFormulas
com.apple.iWork.pasteboardState.numberOfRowsInFirstTable-1
com.apple.iWork.pasteboardState.drawableInfoKinds-1
com.apple.iWork.pasteboardState.countOfObject-1
com.apple.iWork.pasteboardState.hasPastableFormulas
com.apple.iWork.pasteboardState.numberOfTables-1
com.apple.iWork.pasteboardState.applicationName-Numbers
com.apple.iWork.pasteboardState.hasTables
com.apple.iWork.pasteboardState.numberOfColumnsInFirstTable-3
com.apple.iWork.pasteboardState.documentld-6587220130357466587
com.apple.flat-rtfd
NeXT RTFD pasteboard type
com.apple.webarchive
Apple Web Archive pasteboard type
public.rtf
NeXT Rich Text Format v1.0 pasteboard type
public.utf16-external-plain-text
‘ut16’ (CorePasteboardFlavorType 0x75743136)
public.utf8-plain-text
NSStringPboardType
public.html
Apple HTML pasteboard type
public.png
Apple PNG pasteboard type
com.adobe.pdf
Apple PDF pasteboard type
public.tiff
NeXT TIFF v4.0 pasteboard type

Dave

1 Like

No disagreement here. With the proliferation of system-wide data types for all kinds of formatted content, we’re seeing clipboards that use them all, in order to be as compatible as possible with whatever might later want to paste the content.

And it’s all possible due to the “take ownership” clipboard model. No app would be crazy enough to pre-render 40 different representations, but it’s really easy to just advertise them all and render a single representation on-demand when a paste operation happens.

As far as I know, the only place I’ve routinely encountered this is with Microsoft Office. The annoyance there is when they don’t follow normal rules. Excel has this strange thing where saving the file empties the (Excel) clipboard. So if you’re routinely saving your work, and you want to do a precautionary save while you’re copying things around, you have to do save, then copy, then paste. If you copy and then save before you paste, your paste won’t work.

Dave

1 Like

I think most apps use the take-ownership mechanism. But they may automatically upload clipped data when quitting, vs. MS Office, which asks you about it if the amount of clipped data is large.

WRT Excel, their clipboard behavior in general is weird. Even within the app, if you copy/cut a range of cells, you can paste it with CMD-V many times, but if you type “Enter”, it will perform a single paste and will then clear the clipboard. And yes, saving the document also clears it.

I’m not sure what the ultimate goal is with this behavior, but it’s been part of Excel for a very long time. I don’t think it clears the clipboard if some other app owns it (e.g. if you copied from elsewhere), but I haven’t tested it very thoroughly.

That having been said, I always consider the clipbaord to be ephemeral. I don’t expect the data to last long, so I make a point of not copying until I’m ready to paste.